Skip to content

regexCharacterClassRanges

Reports character class elements that can be simplified to ranges.

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

Character class ranges in regular expressions are more concise than listing individual consecutive characters. When four or more consecutive characters appear in a character class, they can be combined into a range for better readability.

const letters = /[abcd]/;
const digits = /[0123]/;
const uppercase = /[ABCD]/;
const mixedWithRange = /[a-cd]/;

This rule is not configurable.

If you prefer listing individual characters for clarity (for example, when the characters represent specific values rather than a range), you might prefer to disable this rule. Some developers find explicit character lists easier to understand when the character set represents distinct concepts.

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