Skip to content

regexConciseCharacterClassNegations

Reports negated character classes that can use shorthand escapes.

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

Enforces using shorthand escape sequences like \D, \W, \S, and \P instead of negated character classes. For example, [^\d] can be written more concisely as \D.

const pattern = /[^\d]/;
const pattern = /[^\w]+/;
const pattern = /[^\s]/;
const pattern = /[^\p{Letter}]/u;

This rule is not configurable.

If you prefer the explicit negation syntax [^\d] for readability, or if your codebase has an established convention using negated character classes, you might prefer to disable this rule.

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