Braced Hex Escape Without /u

Identifier: regex.lint.unicode.bracedHexWithoutU

When it triggers: A braced escape \x{...} names a code point above U+FF, and the pattern has neither /u nor (*UTF). Unlike the three rules above, the pattern does not even compile in byte mode — PCRE2 refuses it — so validation reports it first, and the lint id names the same defect on a parsed tree, at error severity.

Example:

// FAIL (validation): Invalid code point "\x{100}":
//      without the "u" flag, a character is at most \xFF.
preg_match('/\x{100}/', $input);

// PREFERRED
preg_match('/\x{100}/u', $input);

Fix: Add /u.


Try it. Open /\x{100}/ in the playground: the Diagnostics tab shows what PHP prints and the code PHPRegex gives it.

Edit on GitHub Feedback