regexControlCharacterEscapes
Reports control characters that are not escaped using standard escape sequences.
✅ This rule is included in the tslogicalandlogicalStrictpresets.
Enforces consistent escaping of control characters in regular expressions by requiring standard escape sequences (\0, \t, \n, \v, \f, \r) instead of hex, unicode, or control character escapes.
Examples
Section titled “Examples”Hex Escapes
Section titled “Hex Escapes”const pattern = /\x0a/;const pattern = /\n/;Unicode Escapes
Section titled “Unicode Escapes”const pattern = /\u000a/;const pattern = /\n/;Control Character Escapes
Section titled “Control Character Escapes”const pattern = /\cJ/;const pattern = /\n/;Unicode Code Point Escapes
Section titled “Unicode Code Point Escapes”const pattern = /\u{a}/u;const pattern = /\n/u;Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”If your codebase has an established convention of using hex or unicode escapes for control characters, or if you need consistency with generated code that uses these formats, you may disable this rule.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- ESLint:
regexp/control-character-escape
Made with ❤️🔥 in Boston by
Josh Goldberg and contributors.