regexEscapeBackspaces
Reports escape backspace (
[\b]) in character classes.
✅ This rule is included in the tsstylisticandstylisticStrictpresets.
Reports the use of \b inside character classes to match the backspace character (U+0008).
The word boundary assertion (\b) and the escape backspace ([\b]) look identical, which can cause confusion.
Examples
Section titled “Examples”Escape Backspace in Character Class
Section titled “Escape Backspace in Character Class”Using \b inside a character class matches the backspace character, not a word boundary.
const pattern = /[\b]/;const pattern = /[\u0008]/;Mixed Character Class
Section titled “Mixed Character Class”Even with other characters in the class, \b should be replaced.
const pattern = /[a\b]/;const pattern = /[a\u0008]/;RegExp Constructor
Section titled “RegExp Constructor”The rule also checks regex patterns in RegExp constructor calls.
const pattern = new RegExp("[\\b]");const pattern = new RegExp("[\\u0008]");Word Boundary Is Valid
Section titled “Word Boundary Is Valid”The word boundary assertion \b outside character classes is valid and not reported.
const pattern = /\bword\b/;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 established conventions for using [\b] and all developers working on it understand the differences, you might prefer to disable this rule.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- ESLint:
regexp/no-escape-backspace
Made with ❤️🔥 in Boston by
Josh Goldberg and contributors.