Quantifier After a Multibyte Character

Identifier: regex.lint.unicode.quantifiedMultibyteWithoutU

When it triggers: A quantifier follows a character of two bytes or more, and the pattern has neither /u nor (*UTF). The quantifier repeats the last byte only.

Example:

// ERROR: + repeats \xA9, the last byte of "é"
preg_match('/^é+$/', 'éé');      // 0
preg_match('/^é+$/', "é\xA9");   // 1

// PREFERRED
preg_match('/^é+$/u', 'éé');     // 1
preg_match('/^(?:é)+$/', 'éé');  // 1, still byte mode

Fix: Add /u, or group the character so the quantifier takes all of it.


Try it. Open /^é+$/ in the playground: the finding is in the Diagnostics tab.

Edit on GitHub Feedback