no-control-regex
Configuration
Rule Details
Disallows control characters (U+0000 through U+001F) in regular expressions. Control characters are rarely intended in patterns and usually indicate a typo.
The rule flags:
- Unescaped raw characters in the U+0000–U+001F range
\xHHescapes withHHin00–1F\uHHHHescapes withHHHHin0000–001F\u{H...}escapes (under theuorvflag) resolving to U+0000–U+001F
Symbolic control escapes such as \t, \n, \r, \v, \f, \0, and \cX are allowed.
Examples of incorrect code for this rule:
Examples of correct code for this rule:
Differences from ESLint
ESLint's implementation delegates pattern validation to @eslint-community/regexpp and wraps it in try/catch. On a regex-syntax error, regexpp aborts parsing, so any control characters appearing after the error point are never reported.
This implementation is a linear scanner without a full ES regex parser. On a syntactically-invalid pattern it keeps scanning past the error, which may surface control characters ESLint would have suppressed. For valid regex patterns the two implementations produce identical output.
Syntactically-invalid patterns are independently flagged by the no-invalid-regexp rule, so running both rules together surfaces every relevant issue; only the rule attribution differs on malformed input.