{"record":{"id":"216e7b5f26e47437","repo":"rectorphp/rector","slug":"s-is-deprecated-as-simplifying-regex-ranges-is","errorCode":null,"errorMessage":"\"%s\" is deprecated, as simplifying regex ranges is a personal preference that can worsen readability","messagePattern":"\"(.+?)\" is deprecated, as simplifying regex ranges is a personal preference that can worsen readability","errorType":"exception","errorClass":"ShouldNotHappenException","httpStatus":null,"severity":"error","filePath":"rules/CodeQuality/Rector/FuncCall/SimplifyRegexPatternRector.php","lineNumber":52,"sourceCode":"        preg_match('#[\\w\\d+]#', $value);\n    }\n}\nCODE_SAMPLE\n)]);\n    }\n    /**\n     * @return array<class-string<Node>>\n     */\n    public function getNodeTypes(): array\n    {\n        return [String_::class];\n    }\n    /**\n     * @param String_ $node\n     */\n    public function refactor(Node $node): ?String_\n    {\n        throw new ShouldNotHappenException(sprintf('\"%s\" is deprecated, as simplifying regex ranges is a personal preference that can worsen readability', self::class));\n    }\n}\n","sourceCodeStart":34,"sourceCodeEnd":55,"githubUrl":"https://github.com/rectorphp/rector/blob/408fcb0ff1833e3d26cbc9b04c23a77565814a16/rules/CodeQuality/Rector/FuncCall/SimplifyRegexPatternRector.php#L34-L55","documentation":"SimplifyRegexPatternRector used to shorten regex character ranges inside preg_* pattern strings, e.g. [0-9] to \\d. It is deprecated because such simplification is a personal preference that can worsen readability (\\d is Unicode-aware in some contexts, and [A-Za-z] is more self-documenting than [a-zA-Z] rewrites). refactor() now throws ShouldNotHappenException for every String_ node matched; the rule transforms nothing and exists only to break stale configs loudly.","triggerScenarios":"Registering rules/CodeQuality/Rector/FuncCall/SimplifyRegexPatternRector.php and running rector over any file — the rule matches every String_ node, so the first string literal anywhere triggers the throw at rules/CodeQuality/Rector/FuncCall/SimplifyRegexPatternRector.php:52.","commonSituations":"Old configs with fine-grained CodeQuality rule lists or copied rule sets from tutorials still contain SimplifyRegexPatternRector after upgrading. Because String_ matches nearly every file, the crash occurs on the first analysed file and is often mistaken for a corrupted installation.","solutions":["Remove SimplifyRegexPatternRector::class from rector.php and all imported set files, then re-run vendor/bin/rector dry-run","If you want regex hygiene, review preg_ patterns manually or lint them with a dedicated regex tool","Write a small custom rule if your team mandates [0-9] -> \\d","grep -r SimplifyRegexPatternRector . to catch indirect registrations"],"exampleFix":"// before (rector.php)\n->withRules([\n    \\Rector\\CodeQuality\\Rector\\FuncCall\\SimplifyRegexPatternRector::class,\n])\n\n// after\n// rule removed; regexes untouched:\npreg_match('/[0-9]+/', $value); // stays as is","handlingStrategy":"validation","validationCode":"$deprecated = ['SimplifyRegexPatternRector'];\nforeach (glob(__DIR__ . '/rector*.php') as $config) {\n    $src = file_get_contents($config);\n    foreach ($deprecated as $rule) {\n        if (str_contains($src, $rule)) {\n            fwrite(STDERR, \"Remove deprecated rule {$rule} from {$config}\\n\");\n            exit(1);\n        }\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Review regex style manually instead of automating range simplification","Drop deprecated rules from rector.php before upgrading Rector","Validate configs in CI with a dry-run against a fixture file","Avoid String_-matching style rules; they touch nearly every file and fail loudly"],"tags":["rector","php","deprecated-rule","regex","code-style"],"backgroundTag":"rector-deprecated-rule","analyzedSha":"408fcb0ff1833e3d26cbc9b04c23a77565814a16","analyzedAt":"2026-08-21T05:11:02.643Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}