no-useless-backreference
Configuration
rslint.config.ts
Rule Details
This rule disallows useless backreferences in regular expressions — backreferences that can only ever match the empty string regardless of input. The rule recognizes five problematic patterns:
- A backreference to a group that contains the backreference itself (the group hasn't matched yet when the backreference starts).
- A backreference that appears before the group it refers to (forward reference).
- A backreference inside a lookbehind that refers to a group appearing before it in the same lookbehind (lookbehind matches right-to-left).
- A backreference and its referenced group are in different alternatives of the same disjunction.
- A backreference to a group inside a negative lookaround when the backreference itself is outside that lookaround (the group's match was discarded).
Examples of incorrect code for this rule:
Examples of correct code for this rule:
Options
This rule has no options.