Skip to content

regexInvisibleCharacters

Reports invisible characters in regex patterns that should use escape sequences instead.

✅ This rule is included in the ts logical and logicalStrict presets.

Invisible characters like tabs, non-breaking spaces, zero-width spaces, and other whitespace characters are difficult to distinguish visually. When these characters appear literally in regex patterns, they can lead to confusion and hard-to-debug issues. Using explicit escape sequences makes the intent clear and the code more maintainable.

Regular spaces (U+0020) are allowed since they are commonly visible in most editors and fonts.

76// Tab character embedded in regex (invisiblAEconsB0patteAE< =sp ansty="le--0:#5CA7E4;--1:#3A68">81<1/sp ansty="le--0:#5CA7E4;--1:#3A68">8F< sp ansty="le--0:#D9F5DD;--1:#1111">1<1/sp ansty="le--0:#D6DEEB;--1:#403F">5<3;d ivclassNa="meco">76// Non-breaking space embedded in regAEconsB0patteAE< =sp ansty="le--0:#5CA7E4;--1:#3A68">81<1/sp ansty="le--0:#5CA7E4;--1:#3A68">81<1/sp ansty="le--0:#D6DEEB;--1:#403F">5<3;d ivclassNa="meco">76// Zero-width space embedded in regAEconsB0patteAE< =sp ansty="le--0:#5CA7E4;--1:#3A68">81<1/sp ansty="le--0:#5CA7E4;--1:#3A68">81<111/ spans="tyle--0:#D6DEEB;--1:#40">3
<​/;divstarlight-ta b-itemdat="aLabel✅">< Co rrectdivc="lassNameexpress"><-contentfi gcaptionc="lassNa">:#8844:#3B61B<0pat terns="panstyle--0:#C792EA;--1">:#<8844 AE =s="panstyle--0:#5CA7E4;--1">:<#3A6 88F s="panstyle--0:#D9F5DD;--1">:<#111 111/s="panstyle--0:#F78C6C;--1">:#AA<0982 \x09s="panstyle--0:#D9F5DD;--1">:<#111 111/s="panstyle--0:#D6DEEB;--1">:<#40 3F53;divc="lass">< /\><-contentfi gcaptionc="lassNa">:#8844:#3B61B<0pat terns="panstyle--0:#C792EA;--1">:#<8844 AE =s="panstyle--0:#5CA7E4;--1">:<#3A6 88F s="panstyle--0:#D9F5DD;--1">:<#111 111/s="panstyle--0:#F78C6C;--1">:#AA<0982 \xA0s="panstyle--0:#D9F5DD;--1">:<#111 111/s="panstyle--0:#D6DEEB;--1">:<#40 3F53;divc="lass">< /\><-contentfi gcaptionc="lassNa">:#8844:#3B61B<0pat terns="panstyle--0:#C792EA;--1">:#<8844 AE =s="panstyle--0:#5CA7E4;--1">:<#3A6 88F s="panstyle--0:#D9F5DD;--1">:<#111 111/s="panstyle--0:#F78C6C;--1">:#AA09<82\u 200Bs="panstyle--0:#D9F5DD;--1">:<#111 111/s="panstyle--0:#D6DEEB;--1">:<#40 3F53;divc="lass"><\u2><00B /;divdivc="lassNameexpress"><-contentfi gcaptionc="lassNa">:#5D6376// Regular space is< al loweddivc="lassNam">:#8844:#3B61B<0pat terns="panstyle--0:#C792EA;--1">:#<8844 AE =s="panstyle--0:#5CA7E4;--1">:<#3A6 88F s="panstyle--0:#D9F5DD;--1">:<#111 111/s="panstyle--0:#5CA7E4;--1">:<#3A6 88F s="panstyle--0:#D9F5DD;--1">:<#111 111/s="panstyle--0:#D6DEEB;--1">:<#40 3F53;divc="lass">< / /;divdivc="lassNameexpress"><-contentfi gcaptionc="lassNa">:#5D6376// Standard escape sequences :#8844:#3B61B<0pat terns="panstyle--0:#C792EA;--1">:#<8844 AE =s="panstyle--0:#5CA7E4;--1">:<#3A6 88F s="panstyle--0:#D9F5DD;--1">:<#111 111/s="panstyle--0:#82AAFF;--1">:#3B61:<#111 111/s="panstyle--0:#D6DEEB;--1">:<#40 3F53;divc="lass"><\t\>

This rule is not configurable.

If you have tooling that renders invisible characters distinctively, or if your codebase intentionally uses literal invisible characters in regex patterns for specific matching requirements, you might prefer to disable this rule. Some specialized text processing may require literal invisible character matching.