Skip to content

regexDollarEscapes

Reports replacement strings with unescaped $ that should use $$.

✅ This rule is included in the ts stylistic and stylisticStrict presets.

Enforces escaping the $ character as $$ when using it literally in the replacement argument of String.prototype.replace() and String.prototype.replaceAll().

In these methods, $ has special meaning for substitution patterns like $& (matched substring), $1 (first capture group), etc. An unescaped $ followed by an unrecognized character will be treated as a literal $, but this behavior is confusing and error-prone.

This rule reports unescaped $ characters in replacement strings that are not valid substitution pattern matchers.

AEconsB0resuAE <= sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4D<€100 spans="tyle--0:#D9F5DD;--1:#11">1<111" spans="tyle--0:#C792EA;--1:#88">4<4AE. spans="tyle--0:#82AAFF;--1:#3B">61B0rep31<111/ spans="tyle--0:#5CA7E4;--1:#3A">6<88 F€spa="nstyle--0:#D9F5DD;--1:#">1<1111 1/spa="nstyle--0:#C792EA;--1:#">88<44AE , spa="nstyle--0:#D9F5DD;--1:#">1<1111 1"spa="nstyle--0:#ECC48D;--1:#">9<84E4 D$spa="nstyle--0:#D9F5DD;--1:#">1<1111 1"spa="nstyle--0:#D6DEEB;--1:#">40<3F5 3);divcla="ssNa">
<, "$");divstarligh t-tab-ite="mdataLabe">< not-conte ntfigcapt="ioncla">;--1:#<8844 AEcon="st spanstyle--0:#82AAFF">;--1:#<3B61 B0res="ultspanstyle--0:#C792EA">;--<1:#8 844AE=" = spanstyle--0:#D9F5DD">;<--1: #1111="11"spanstyle--0:#ECC48D">;--1<:#98 4E4="D€100spanstyle--0:#D9F5">DEFF;--1:<#3B6 1B0re="placespanstyle--0:#D6DE">EDE<4;-- 1:#3A="688F€spanstyle--0:#D9">F<5DD; --1:#="111111/spanstyle--0:#C7">92F<5DD; --1:#="111111"spanstyle--0:#EC">C4<8D;- -1:#9="84E4D$$spanstyle--0:#D9">F<5DD; --1:#="111111"spanstyle--0:#D6">DE

Dollar Before Invalid Substitution Character

Section titled “Dollar Before Invalid Substitution Character”
AEconsB0resuAE <= sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4Da1<1"sp ansty="le--0:#C792EA;--1:#8844">AB0repla5<3(sp ansty="le--0:#D9F5DD;--1:#1111">1<1/sp ansty="le--0:#82AAFF;--1:#3B61">B<0.sp ansty="le--0:#D9F5DD;--1:#1111">1<1/sp ansty="le--0:#C792EA;--1:#8844">AE<, sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4D<$xsp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#D6DEEB;--1:#403F">53<);d ivclassNa="meco"><);d>
44AEco61B0re44A1<111" spans="tyle--0:#ECC48D;--1:#98">4E41<111" spans="tyle--0:#C792EA;--1:#88">4<4AE. spans="tyle--0:#82AAFF;--1:#3B">61B0rep31<111/ spans="tyle--0:#82AAFF;--1:#3B">6<1B0. spans="tyle--0:#D9F5DD;--1:#11">1<111/ spans="tyle--0:#C792EA;--1:#88">441<111" spans="tyle--0:#ECC48D;--1:#98">4E41<111" spans="tyle--0:#D6DEEB;--1:#40">3F<53) ;divclass="Name">
AEconsB0matchedSubstriAE <= sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4Da1<1"sp ansty="le--0:#C792EA;--1:#8844">AB0repla5<3(sp ansty="le--0:#D9F5DD;--1:#1111">1<1/sp ansty="le--0:#82AAFF;--1:#3B61">B<0.sp ansty="le--0:#D9F5DD;--1:#1111">1<1/sp ansty="le--0:#C792EA;--1:#8844">AE<, sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4D<$&sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#D6DEEB;--1:#403F">53<);d ivclassNa="meec-li">AEconsB0firstGroAE <= sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4Da1<1"sp ansty="le--0:#C792EA;--1:#8844">AB0repla5<3(sp ansty="le--0:#D9F5DD;--1:#1111">1<1/sp ansty="le--0:#5CA7E4;--1:#3A68">8B<0.sp ansty="le--0:#5CA7E4;--1:#3A68">81<1/sp ansty="le--0:#C792EA;--1:#8844">AE<, sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4D<$1sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#D6DEEB;--1:#403F">53<);d ivclassNa="meec-li">AEconsB0namedGroAE <= sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4Da1<1"sp ansty="le--0:#C792EA;--1:#8844">AB0repla5<3(sp ansty="le--0:#D9F5DD;--1:#1111">1<1/sp ansty="le--0:#5CA7E4;--1:#3A68">8F(B0ch8sp ansty="le--0:#82AAFF;--1:#3B61">Bsp><0.sp ansty="le--0:#5CA7E4;--1:#3A68">81<1/sp ansty="le--0:#C792EA;--1:#8844">AE<, sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4D$<chasp ansty="le--0:#D9F5DD;--1:#1111">1sp><1"sp ansty="le--0:#D6DEEB;--1:#403F">53<);d ivclassNa="meec-li">AEconsB0literalDollAE <= sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4Da1<1"sp ansty="le--0:#C792EA;--1:#8844">AB0repla5<3(sp ansty="le--0:#D9F5DD;--1:#1111">1<1/sp ansty="le--0:#82AAFF;--1:#3B61">B<0.sp ansty="le--0:#D9F5DD;--1:#1111">1<1/sp ansty="le--0:#C792EA;--1:#8844">AE<, sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4D<$$sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#D6DEEB;--1:#403F">53<);d ivclassNa="meco"><);d>

This rule is not configurable.

If you intentionally rely on the behavior where $ followed by an unrecognized character produces a literal $, you might prefer to disable this rule.