regexContradictoryAssertions
Reports elements in regular expressions that contradict assertions.
✅ This rule is included in the ts logical presets.
Reports elements in regular expressions that contradict assertions like word boundaries (\b).
These contradictions indicate dead code or unintended behavior in the regex pattern.
Examples
Section titled “Examples”Quantifier Always Entered
Section titled “Quantifier Always Entered”When a word boundary is between two word characters (or two non-word characters), optional quantifiers following it are always entered.
const pattern = /a\b-?a/;const pattern = /a\b-a/;Quantifier Cannot Be Entered
Section titled “Quantifier Cannot Be Entered”When a word boundary assertion forces a transition that conflicts with the quantifier’s element, the quantifier can never match.
const pattern = /a\ba*-/;const pattern = /a\b-/;RegExp Constructor
Section titled “RegExp Constructor”The rule also checks regex patterns in RegExp constructor calls.
const pattern = new RegExp("a\\b-?a");const pattern = new RegExp("a\\b-a");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 contradictory assertions for documentation purposes or if you’re working with dynamically constructed regex patterns where the contradictions are not actually problematic, you may disable this rule.