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 pattern = /(?=)/;const pattern = /(?=\d)/;Empty Negative Lookahead
Section titled “Empty Negative Lookahead”const pattern = /(?!)/;const pattern = /(?!\d)/;Empty Lookbehind
Section titled “Empty Lookbehind”const pattern = /(?<=)/;const pattern = /(?<=\d)/;Lookahead with Optional Content
Section titled “Lookahead with Optional Content”const pattern = /(?=a?)/;const 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.