regexObscureRanges
Reports obscure character ranges in regular expressions.
✅ This rule is included in the ts logical presets.
Character ranges like A-z or 0-A span across non-obvious character sets and can lead to unexpected matching behavior.
Standard alphanumeric ranges like a-z, A-Z, and 0-9 are preferable.
This rule reports obscure character ranges in regular expressions.
Examples
Section titled “Examples”Cross-Case Range
Section titled “Cross-Case Range”const pattern = /[A-z]/;const pattern = /[A-Za-z]/;The range A-z includes characters like [, \, ], ^, _, and backtick in addition to letters.
Digit to Letter Range
Section titled “Digit to Letter Range”const pattern = /[0-A]/;const pattern = /[0-9A]/;Mixed Escape Sequence Range
Section titled “Mixed Escape Sequence Range”const pattern = /[\cA-Z]/;const pattern = /[\cA-\cZ]/;Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”If you intentionally use non-standard character ranges for specific matching needs, or if your codebase has established patterns that rely on these ranges, you might want to disable this rule.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- ESLint:
regexp/no-obscure-range
Made with ❤️🔥 in Boston by
Josh Goldberg and contributors.