regexControlCharacters
Reports control characters in regular expressions.
✅ This rule is included in the ts logical presets.
Reports control characters (code points U+0000 through U+001F) in regular expressions. Control characters in regex patterns are rarely intentional and can indicate a mistake or copy-paste error.
Examples
Section titled “Examples”Hex Escapes
Section titled “Hex Escapes”const pattern = /\x1f/;const pattern = /\x20/;Unicode Escapes
Section titled “Unicode Escapes”const pattern = /\u001f/;const pattern = /\u0020/;Control Character Escapes
Section titled “Control Character Escapes”const pattern = /\cA/;const pattern = /a/;Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”If your application intentionally processes binary data or protocols that use control characters, and you need to match them in regular expressions, you might prefer to disable this rule.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- Biome:
noControlCharactersInRegex - Deno:
no-control-regex - ESLint:
no-control-regexregexp/no-control-character - Oxlint:
eslint/no-control-regex
Made with ❤️🔥 in Boston by
Josh Goldberg and contributors.