{"record":{"id":"1e106c0eb5ed42a8","repo":"rectorphp/rector","slug":"an-invalid-or-unsupported-character-class-s","errorCode":null,"errorMessage":"an invalid or unsupported character class [%s]","messagePattern":"an invalid or unsupported character class \\[(.+?)\\]","errorType":"validation","errorClass":"InvalidEregException","httpStatus":null,"severity":"error","filePath":"rules/Php70/EregToPcreTransformer.php","lineNumber":290,"sourceCode":"            $r[$rr] .= '{' . $matches[self::MINIMAL_NUMBER_PART] . '}';\n        }\n        return $ii + 1;\n    }\n    /**\n     * @return int[]|string[]\n     */\n    private function processCharacterClass(string $content, int $i, string $cls): array\n    {\n        $offset = $i;\n        $ii = strpos($content, ']', $offset);\n        if ($ii === \\false) {\n            throw new InvalidEregException('\"[\" does not have a matching \"]\"');\n        }\n        $start = $i + 1;\n        $length = $ii - ($i + 1);\n        $ccls = Strings::substring($content, $start, $length);\n        if (!isset(self::CHARACTER_CLASS_MAP[$ccls])) {\n            throw new InvalidEregException('an invalid or unsupported character class [' . $ccls . ']');\n        }\n        $cls .= self::CHARACTER_CLASS_MAP[$ccls];\n        $i = $ii + 1;\n        return [$cls, $i];\n    }\n}\n","sourceCodeStart":272,"sourceCodeEnd":297,"githubUrl":"https://github.com/rectorphp/rector/blob/408fcb0ff1833e3d26cbc9b04c23a77565814a16/rules/Php70/EregToPcreTransformer.php#L272-L297","documentation":"processCharacterClass() recognized a POSIX bracket class '[[:...:]]' and looked the inner name up in CHARACTER_CLASS_MAP, which supports only alnum, alpha, blank, cntrl, digit, graph, lower, print, punct, space, upper, xdigit. The name was not found, so InvalidEregException('an invalid or unsupported character class [name]') is thrown (EregToPcreTransformer.php:290) and the ereg-to-preg conversion aborts.","triggerScenarios":"Rector (Php70 set / EregToPregMatchRector, target PHP >= 7.0) processes an ereg-family call whose literal pattern uses a bracket class outside the supported list, e.g. `ereg('[[:word:]]', $s)` (word is a GNU extension, not mapped), `split('[[:foo:]]', $s)`, or typo'd names like '[[:diget:]]'. The isset() on CHARACTER_CLASS_MAP fails and the offending class name is embedded in the message.","commonSituations":"Patterns ported from GNU grep/sed that support extra classes ('[[:word:]]'); PCRE-style '\\w' habits translated to a nonexistent '[[:word:]]'; typo'd class names inside old validation patterns for emails, zip codes, etc.","solutions":["Replace the unsupported class in the flagged pattern with a supported equivalent: '[[:word:]]' -> '[A-Za-z0-9_]'.","Check the name against the supported list (alnum, alpha, blank, cntrl, digit, graph, lower, print, punct, space, upper, xdigit) and fix typos like '[[:diget:]]' -> '[[:digit:]]'.","Re-run rector; preflight literal ereg patterns for '[[:...:]]' names not in that list."],"exampleFix":"// before - unsupported class\nereg('[[:word:]]', $subject);\n\n// after - supported equivalent\nereg('[[:alnum:]_]', $subject); // rector: preg_match('#[[:alnum:]_]#m', $subject)","handlingStrategy":"validation","validationCode":"const SUPPORTED = ['alnum','alpha','blank','cntrl','digit','graph','lower','print','punct','space','upper','xdigit'];\nif (preg_match_all('~\\[\\[:([a-z]+):\\]~', $pattern, $m)) {\n    foreach ($m[1] as $name) {\n        if (!in_array($name, SUPPORTED, true)) {\n            throw new InvalidArgumentException(\"unsupported POSIX class [[:{$name}:]]\");\n        }\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    $pcre = $eregToPcreTransformer->transform($pattern, $ignoreCase);\n} catch (InvalidEregException $e) {\n    // class name not in the supported 13 — substitute an equivalent and re-run\n    continue;\n}","preventionTips":["Restrict POSIX classes to the supported set: alnum, alpha, blank, cntrl, digit, graph, lower, print, punct, space, upper, xdigit.","Replace '[[:word:]]' with '[A-Za-z0-9_]' — it is a GNU extension Rector cannot convert.","Spell-check class names ('diget' vs 'digit') when linting legacy patterns."],"tags":["rector","php","regex","posix-ere","character-class","migration"],"backgroundTag":"invalid-regex-syntax","analyzedSha":"408fcb0ff1833e3d26cbc9b04c23a77565814a16","analyzedAt":"2026-08-21T05:11:02.643Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}