|
23 | 23 | - [Advanced Usage](#advanced-usage) |
24 | 24 | - [Parsing bare patterns vs PCRE strings](#parsing-bare-patterns-vs-pcre-strings) |
25 | 25 | - [Working with the AST](#working-with-the-ast) |
26 | | - - [Writing a custom AST visitor](#writing-a-custom-ast-visitor) |
27 | | - - [Optimizing and recompiling patterns](#optimizing-and-recompiling-patterns) |
| 26 | + - [Writing a custom AST visitor](#writing-a-custom-ast-visitor) |
| 27 | + - [Optimizing and recompiling patterns](#optimizing-and-recompiling-patterns) |
| 28 | + - [Auto-Modernize Legacy Patterns](#auto-modernize-legacy-patterns) |
| 29 | + - [Syntax Highlighting](#syntax-highlighting) |
28 | 30 | - [ReDoS Analysis](#redos-analysis) |
29 | 31 | - [What is ReDoS?](#what-is-redos) |
30 | 32 | - [How RegexParser detects it](#how-regexparser-detects-it) |
@@ -321,6 +323,58 @@ This makes it easy to implement automated refactorings (via Rector) or style rul |
321 | 323 |
|
322 | 324 | --- |
323 | 325 |
|
| 326 | +## ✨ Auto-Modernize Legacy Patterns |
| 327 | +
|
| 328 | +Clean up messy or legacy regexes automatically: |
| 329 | +
|
| 330 | +```php |
| 331 | +use RegexParser\Regex; |
| 332 | +
|
| 333 | +$regex = Regex::create(); |
| 334 | +$modern = $regex->modernize('/[0-9]+\-[a-z]+\@(?:gmail)\.com/'); |
| 335 | +
|
| 336 | +echo $modern; // Outputs: /\d+-[a-z]+@gmail\.com/ |
| 337 | +``` |
| 338 | +
|
| 339 | +**What it does:** |
| 340 | +- Converts `[0-9]` → `\d`, `[a-zA-Z0-9_]` → `\w`, `[\t\n\r\f\v]` → `\s` |
| 341 | +- Removes unnecessary escaping (e.g., `\@` → `@`) |
| 342 | +- Modernizes backrefs (`\1` → `\g{1}`) |
| 343 | +- Preserves exact behavior — no functional changes |
| 344 | +
|
| 345 | +Perfect for refactoring legacy codebases or cleaning up generated patterns. |
| 346 | +
|
| 347 | +--- |
| 348 | +
|
| 349 | +## 🎨 Syntax Highlighting |
| 350 | +
|
| 351 | +Make complex regexes readable with automatic syntax highlighting: |
| 352 | +
|
| 353 | +```php |
| 354 | +use RegexParser\Regex; |
| 355 | +
|
| 356 | +$regex = Regex::create(); |
| 357 | +
|
| 358 | +// For console output |
| 359 | +echo $regex->highlightCli('/^[0-9]+(\w+)$/'); |
| 360 | +// Outputs: ^[0-9]+(\w+)$ with ANSI colors |
| 361 | +
|
| 362 | +// For web display |
| 363 | +echo $regex->highlightHtml('/^[0-9]+(\w+)$/'); |
| 364 | +// Outputs: <span class="regex-anchor">^</span>[<span class="regex-type">\d</span>]+(<span class="regex-type">\w</span>+)$ |
| 365 | +``` |
| 366 | +
|
| 367 | +**Color Scheme:** |
| 368 | +- **Meta-characters** (`(`, `)`, `|`, `[`, `]`): Blue - Structure |
| 369 | +- **Quantifiers** (`*`, `+`, `?`, `{...}`): Yellow - Repetition |
| 370 | +- **Escapes/Types** (`\d`, `\w`, `\n`): Green - Special chars |
| 371 | +- **Anchors/Assertions** (`^`, `$`, `\b`): Magenta - Boundaries |
| 372 | +- **Literals**: Default - Plain text |
| 373 | +
|
| 374 | +HTML output uses `<span class="regex-*">` classes for easy styling. |
| 375 | +
|
| 376 | +--- |
| 377 | +
|
324 | 378 | ## ReDoS Analysis |
325 | 379 |
|
326 | 380 | ### What is ReDoS? |
@@ -519,6 +573,18 @@ If you maintain custom visitors, plan to adjust them when new nodes appear. Brea |
519 | 573 |
|
520 | 574 | --- |
521 | 575 |
|
| 576 | +## Known Limitations |
| 577 | +
|
| 578 | +While this library supports a comprehensive set of PCRE2 features, some highly specific or experimental features may not be fully supported yet. For example: |
| 579 | +
|
| 580 | +- Certain Perl-specific verbs not yet standardized in PCRE2. |
| 581 | +- Advanced Unicode features beyond basic properties and escapes. |
| 582 | +- Experimental or platform-specific extensions. |
| 583 | +
|
| 584 | +If you encounter an unsupported feature, please [open an issue](https://github.com/yoeunes/regex-parser/issues) with a test case. |
| 585 | +
|
| 586 | +--- |
| 587 | +
|
522 | 588 | ## Contributing |
523 | 589 |
|
524 | 590 | Contributions are welcome! Areas where help is especially useful: |
|
0 commit comments