Skip to content

regexContradictoryAssertions

Reports elements in regular expressions that contradict assertions.

✅ This rule is included in the ts logical and logicalStrict 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.

When a word boundary is between two word characters (or two non-word characters), optional quantifiers following it are always entered.

AEconsB0patteAE< =sp ansty="le--0:#5CA7E4;--1:#3A68">81<1/sp ansty="le--0:#5CA7E4;--1:#3A68">8AE<\bsp ansty="le--0:#5CA7E4;--1:#3A68">87<2?sp ansty="le--0:#5CA7E4;--1:#3A68">81<1/sp ansty="le--0:#D6DEEB;--1:#403F">5<3;d ivclassNa="meco">
44AEco61B0pat446<88F spans="tyle--0:#D9F5DD;--1:#11">1<111/ spans="tyle--0:#5CA7E4;--1:#3A">6<88Fa spans="tyle--0:#C792EA;--1:#88">4468<8F-a spans="tyle--0:#D9F5DD;--1:#11">1<111/ spans="tyle--0:#D6DEEB;--1:#40">3<-a/>

When a word boundary assertion forces a transition that conflicts with the quantifier’s element, the quantifier can never match.

AEconsB0patteAE< =sp ansty="le--0:#5CA7E4;--1:#3A68">81<1/sp ansty="le--0:#5CA7E4;--1:#3A68">8AE<\bsp ansty="le--0:#5CA7E4;--1:#3A68">87<2*sp ansty="le--0:#5CA7E4;--1:#3A68">81<1/sp ansty="le--0:#D6DEEB;--1:#403F">5<3;d ivclassNa="meco">
44AEco61B0pat446<88F spans="tyle--0:#D9F5DD;--1:#11">1<111/ spans="tyle--0:#5CA7E4;--1:#3A">6<88Fa spans="tyle--0:#C792EA;--1:#88">446<88F- spans="tyle--0:#D9F5DD;--1:#11">1<111/ spans="tyle--0:#D6DEEB;--1:#40">3

The rule also checks regex patterns in RegExp constructor calls.

AEconsB0patteAE <= sp ansty="le--0:#7FDBCA;--1:#096E">72nAB0RegE5<3(sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">482<\\sp ansty="le--0:#ECC48D;--1:#984E">4Db-1<1"sp ansty="le--0:#D6DEEB;--1:#403F">53<);d ivclassNa="meco"><);d>
44AEco61B0pat44A6E7<2new spans="tyle--0:#C792EA;--1:#88">4<4AE spans="tyle--0:#82AAFF;--1:#3B">61B0Re31<111" spans="tyle--0:#ECC48D;--1:#98">409<82\\ spans="tyle--0:#ECC48D;--1:#98">4E41<111" spans="tyle--0:#D6DEEB;--1:#40">3F<53) ;divclass="Name">

This rule is not configurable.

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.