regexEmptyLookaroundsAssertions
Reports empty lookahead and lookbehind assertions in regular expressions.
✅ This rule is included in the tslogicalandlogicalStrictpresets.
Reports empty lookahead and lookbehind assertions in regular expressions.
Empty lookarounds like (?=) or (?!) will trivially accept or reject all inputs since they match the empty string.
Examples
Section titled “Examples”Empty Lookahead
Section titled “Empty Lookahead”const const pattern: RegExp
pattern = /(?=)/;const const pattern: RegExp
pattern = /(?=\d)/;Empty Negative Lookahead
Section titled “Empty Negative Lookahead”const const pattern: RegExp
pattern = /(?!)/;const const pattern: RegExp
pattern = /(?!\d)/;Empty Lookbehind
Section titled “Empty Lookbehind”const const pattern: RegExp
pattern = /(?<=)/;const const pattern: RegExp
pattern = /(?<=\d)/;Lookahead with Optional Content
Section titled “Lookahead with Optional Content”const const pattern: RegExp
pattern = /(?=a?)/;const const pattern: RegExp
pattern = /(?=a+)/;Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”If you have a legitimate use case for empty lookarounds in generated or experimental regex patterns, you may disable this rule.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”
Made with ❤️🔥 around the world by
the Flint team and contributors.