Skip to content

regexUnnecessarySetOperands

Reports unnecessary operands in regular expression character class set operations.

✅ This rule is included in the ts logical presets.

Regular expressions with the v flag support character class set operations like intersection (&&) and subtraction (--). This rule identifies operands in these operations that are unnecessary or produce unexpected results.

The rule detects four types of issues:

  1. Disjoint intersection: two sets with no common elements intersected together, producing an empty result.
  2. Subset intersection: a superset operand in an intersection that is redundant.
  3. Disjoint subtraction: subtracting a set that shares no elements, which has no effect.
  4. Subset subtraction: subtracting a superset, which produces an empty result.
1<1/sp ansty="le--0:#82AAFF;--1:#3B61">B0[\w&&\1<1/sp ansty="le--0:#5CA7E4;--1:#3A68">85<3;d ivclassNa="meco">1<1/sp ansty="le--0:#82AAFF;--1:#3B61">B0[\w&&\1<1/sp ansty="le--0:#5CA7E4;--1:#3A68">85<3;d ivclassNa="meco">1<1/sp ansty="le--0:#82AAFF;--1:#3B61">B<0[sp ansty="le--0:#F78C6C;--1:#AA09">82<\wsp ansty="le--0:#82AAFF;--1:#3B61">B0--\1<1/sp ansty="le--0:#5CA7E4;--1:#3A68">85<3;d ivclassNa="meco">1<1/sp ansty="le--0:#82AAFF;--1:#3B61">B<0[sp ansty="le--0:#F78C6C;--1:#AA09">82<\dsp ansty="le--0:#82AAFF;--1:#3B61">B0--\1<1/sp ansty="le--0:#5CA7E4;--1:#3A68">85<3;d ivclassNa="meco">1<1/sp ansty="le--0:#82AAFF;--1:#3B61">B0[[ab8F<&&sp ansty="le--0:#82AAFF;--1:#3B61">B0[de81<1/sp ansty="le--0:#5CA7E4;--1:#3A68">85<3;d ivclassNa="meco">
1<111/ spans="tyle--0:#82AAFF;--1:#3B">6<1B0[ spans="tyle--0:#F78C6C;--1:#AA">09<82\w spans="tyle--0:#82AAFF;--1:#3B">61B0-<-\d] spans="tyle--0:#D9F5DD;--1:#11">1<111/ spans="tyle--0:#5CA7E4;--1:#3A">6<88Fv spans="tyle--0:#D6DEEB;--1:#40">3<]/v><;di vdivclass="Nameexpressive-">1<111/ spans="tyle--0:#82AAFF;--1:#3B">61B0[[68<8F&& spans="tyle--0:#82AAFF;--1:#3B">61B0[6<88F] spans="tyle--0:#D9F5DD;--1:#11">1<111/ spans="tyle--0:#5CA7E4;--1:#3A">6<88Fv spans="tyle--0:#D6DEEB;--1:#40">3<]/v><;di vdivclass="Nameexpressive-">1<111/ spans="tyle--0:#82AAFF;--1:#3B">61B0[[68<8F-- spans="tyle--0:#82AAFF;--1:#3B">61B0[ae6<88F] spans="tyle--0:#D9F5DD;--1:#11">1<111/ spans="tyle--0:#5CA7E4;--1:#3A">6<88Fv spans="tyle--0:#D6DEEB;--1:#40">3<]/v><;di vdivclass="Nameexpressive-">1<111/ spans="tyle--0:#82AAFF;--1:#3B">61B0[\w&<&\s] spans="tyle--0:#D9F5DD;--1:#11">1<111/ spans="tyle--0:#D6DEEB;--1:#40">3<;di vdivclass="Nameexpressive-">1<111/ spans="tyle--0:#82AAFF;--1:#3B">61B0[\1<111/ spans="tyle--0:#5CA7E4;--1:#3A">6<88Fv spans="tyle--0:#D6DEEB;--1:#40">3<]/v>

This rule is not configurable.

If you intentionally use set operations that produce empty results for documentation or testing purposes, you may want to disable this rule.