regexUnnecessaryNestedAssertions
Reports trivially nested assertions in regular expressions that can be simplified.
✅ This rule is included in the ts logical presets.
Regular expression lookarounds are trivially nested when it contains exactly one element that is itself an assertion (anchor or another lookaround of the same direction). Such lookarounds are unnecessary and can be simplified. This rule reports those lookarounds.
Examples
Section titled “Examples”const pattern = /(?=$)/;const boundary = /(?=\b)/;const pattern = /(?=(?=a))/;const behind = /(?<=(?<=a))/;const pattern = new RegExp("(?=$)");const boundary = RegExp("(?=\\b)");const pattern = /$/;const boundary = /\b/;const pattern = /(?=a)/;const behind = /(?<=a)/;const pattern = new RegExp("$");const boundary = RegExp("\\b");Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”If you intentionally keep nested regular expression structures for code clarity or documentation purposes, you might prefer to disable this rule.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”
Made with ❤️🔥 in Boston by
Josh Goldberg and contributors.