Skip to content

regexEscapeBackspaces

Reports escape backspace ([\b]) in character classes.

✅ This rule is included in the ts stylistic and stylisticStrict presets.

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.

Using \b inside a character class matches the backspace character, not a word boundary.

const pattern = /[\b]/;

Even with other characters in the class, \b should be replaced.

const pattern = /[a\b]/;

The rule also checks regex patterns in RegExp constructor calls.

const pattern = new RegExp("[\\b]");

The word boundary assertion \b outside character classes is valid and not reported.

const pattern = /\bword\b/;

This rule is not configurable.

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.

Made with ❤️‍🔥 in Boston by Josh Goldberg and contributors.