Alternation-like Character Classes

Identifier: regex.lint.charclass.suspiciousPipe

When it triggers: A character class contains | alongside many letters, suggesting an alternation typo.

Example:

// WARNING: | is literal inside []
preg_match('/[error|failure]/', $input);

// PREFERRED: Use alternation
preg_match('/(error|failure)/', $input);

Fix: Replace the class with an alternation group when you intend multi-character words.


Try it. Open /[error|failure]/ in the playground: the finding is in the Diagnostics tab.

Edit on GitHub Feedback