Skip to content

regexMisleadingUnicodeCharacters

Reports characters in regex character classes that appear as single visual characters but are made of multiple code points.

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

Some characters that appear as a single visual unit are actually composed of multiple Unicode code points. When these appear in regex character classes, each code point is matched separately, which is typically not the intended behavior.

This rule detects several types of multi-code-point characters in character classes:

  • Surrogate pairs: Characters like 👍 that require two UTF-16 code units
  • Combined characters: Base characters with combining marks like Á (A + combining accent)
  • Emoji with modifiers: Emoji with skin tone modifiers like 👶🏻
  • Regional indicator symbols: Flag emoji like 🇯🇵 (two regional indicators)
  • ZWJ sequences: Characters joined with a zero-width joiner like 👨‍👩‍👦
76// Surrogate pair without unicode flAEconsB0patteAE< =sp ansty="le--0:#5CA7E4;--1:#3A68">81<1/sp ansty="le--0:#82AAFF;--1:#3B61">B0<[👍] spans="tyle--0:#D9F5DD;--1:#11">1<111/ spans="tyle--0:#D6DEEB;--1:#40">3<[👍><]/; divdivcla="ssNameexpressiv">5D6376// Combined character (A + combining a8844AE3B61B0p88<44AE =spa="nstyle--0:#5CA7E4;--1:#">31<1111 1/spa="nstyle--0:#82AAFF;--1:#">3B6<1B0[ Á]sp="anstyle--0:#D9F5DD;--1:">#<1111 11/sp="anstyle--0:#D6DEEB;--1:">#<403 F53;divcl="assN">< /[><Á] /;divdivc="lassNameexpress"><-contentfi gcaptionc="lassNa">:#5D6376// Emoji with skin tone :#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;<--1: #1111="11/spanstyle--0:#5CA7E4">;<--1: #3A68="8Fuspanstyle--0:#D6DEEB">;<--1 :#403F53;="divc"><= /><[ 👶🏻]/u=";divdivclassNam">9F9F;--1:#5D6376// Regional indicato92EA;-<-1:# 8844A="Econst spanstyle--0:#82">AAFF;--<1:#3 B61B0="patternspanstyle--0:#C7">92A<7E4; --1:#="3A688F spanstyle--0:#D9">F<5DD; --1:#="111111/spanstyle--0:#82">AAFF;-<-1:# 3B61B="0[🇯🇵]spanstyle--0">:<#D9F 5DD;-="-1:#111111/spanstyle--0">:<#5CA 7E4;-="-1:#3A688Fuspanstyle--0">:<#D6 DEEB;--1:="#403">e--0:#919F9F;--1:#5D6376// ZWJ< se quence (f="amily e">e--0:#e--0:#8<2AAF F;--1=":#3B61B0patternspanstyl">e-<-0:# C792E="A;--1:#8844AE =spanstyl">e<--0: #5CA7="E4;--1:#3A688F spanstyl">e<--0: #D9F5="DD;--1:#111111/spanstyl">e--0:#82AA�<]spa nstyl="e--0:#D9F5DD;--1:#11111">1F<6DE EB;--1:#="403F53"><;divcl assNa="mecopydivariaLive" politebutt="ontitle" Copy to ="clipboarddataCopiedCopied!dataCode// ZWJ sequence (family emo">
<const pattern = / [👨="‍👩‍�"><�]/ u;divstar="light-tab-itemd">vclassNamecodespanstyle--0:#919F9F;--1:#5D6376// vclass:#8844A#3;<--1: #8844="AE =spanstyle--0:#5CA7E">4<;--1 :#3A6="88F spanstyle--0:#D9F5D">D;--<1:#1 11111="/spanstyle--0:#82AAFF;-">-<1:#3 B61B0="[👍]spanstyle--0:#D9F">57<-con>nedivclassNamecodespanstyle--0:#<919 F9F;--1:#="5D6376/">nedivc;--1:#8<844A Econs="t spanstyle--0:#82AAFF;">--<1:#3 B61B0="patternspanstyle--0:#C7">9<2EA; --1:#="8844AE =spanstyle--0:#5">C9F<5DD; --1:#="111111/spanstyle--0:#5C">A<7E4; --1:#="3A688F👍spanstyle--0:">#<11/ spanstyl="e--0:#">< Ma><const pattern ="= /👍/;divdivcl">< not><-co ntentfigc="aptionc">c-linedivclassNamecodespanst<#5D 6376// Us="e pr">c-line92EA;--<1:#8 844AE="const spanstyle--0:#82A">AF:<#C79 2EA;-="-1:#8844AE =spanstyle--">0<:#5C A7E4;="--1:#3A688F spanstyle--">0:##<82AA FF;--="1:#3B61B0[Á]spanstyle-">-<0:# D9F5DD;--="1:#1"><111 11/spans="tyle--"><0:#D6D EEB;-="-1:#403F53;divcla" ssNamecopy="divaria" Livepoli="tebuttontitleCopy to clipboarddataCopiedCopied!data">eec-linedivclassNamecodespanstyle--0:#919F9F;--<1:# 5D6376// ="Match e">eec-liC792EA;<--1: #8844="AEconst spanstyle--0:#8">2A-<0:#C 792EA=";--1:#8844AE =spanstyle">-<-0:# 5CA7E="4;--1:#3A688F spanstyle">--0:<#D9F 5DD;-="-1:#111111/spanstyle--0">:<#5CA 7E4;-="-1:#3A688F👶🏻spans">t<-1: #111111/="spanst">< se quence ou="tside character">< class const pa="ttern = /👶🏻">classNameec-linedivclassNamecodespanstyle--0:#919F9F<;-- 1:#5D6376="// Use"><\q{ } syntax ="with">< v f lag f="or grapheme clustersdiv">classNyle--0:<#C79 2EA;-="-1:#8844AEconst spansty">le<--0: #82AA="FF;--1:#3B61B0patternsp">apppaanstyle<--0: #F78C="6C;--1:#AA0982\qspansty">l�<}]sp ansty="le--0:#D9F5DD;--1:#1111">1<1/s panstyle-="-0:#"><5CA 7E4;--1:="#3A688">< wi th v flag="for grapheme c"><�🏻}]/v; divdivcla="ssName">scodedivclassNameec-linedivclassNa<#91 9F9F;--1:="#5D6"><376/ / Sol="o regional indicator is"> fineddespans sa8<44AE =spa="nstyle--0:#5CA7E4;--1:#">3A68<8F s panst="yle--0:#D9F5DD;--1:#111">1<11/s panst="yle--0:#82AAFF;--1:#3B6">1:<#11 1111/span="styl"><#3A688 Fuspa="nstyle--0:#D6DEEB" ;--1:#403F="53;divc" lassName="copydivariaLivepolitebuttontitleCopy to clipboarddataCopied">

This rule is not configurable.

If you intentionally want to match individual code points rather than visual characters, or if your regex pattern specifically needs to match partial Unicode sequences, you might prefer to disable this rule. Some specialized text processing may require matching individual surrogate halves or combining marks.