Skip to content

regexDigitMatchers

Reports character classes with multiple adjacent characters that could use a range instead.

✅ This rule is included in the ts stylisticStrict presets.

Enforces using \d instead of [0-9] and \D instead of [^0-9] in regular expressions. The escape sequences are more concise and widely recognized.

const pattern = /[0-9]+/;
const pattern = /[^0-9]/;
const pattern = /[0123456789]/;
const pattern = new RegExp("[0-9]+");

This rule is not configurable.

If your codebase has an established convention of using [0-9] for readability, or if you need consistency with patterns that mix digit ranges with other characters (like [0-9a-f] for hexadecimal), you might prefer to disable this rule.

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