Skip to content

regexAllGlobalFlags

Reports matchAll() and replaceAll() calls with regex arguments missing the global flag.

✅ This rule is included in the ts logical presets.

When calling String.prototype.matchAll() or String.prototype.replaceAll() with a regular expression, the regex must have the global (g) flag. Without it, JavaScript throws a TypeError at runtime.

This rule detects regex literals and RegExp constructor calls that are missing the global flag when passed to these methods.

1<1"sp ansty="le--0:#ECC48D;--1:#984E">4Dhello wor1<1"sp ansty="le--0:#C792EA;--1:#8844">AB0matchA5<3(sp ansty="le--0:#D9F5DD;--1:#1111">1<1/sp ansty="le--0:#5CA7E4;--1:#3A68">81<1/sp ansty="le--0:#D6DEEB;--1:#403F">53<);d ivclassNa="meco"><);d>1<1"sp ansty="le--0:#ECC48D;--1:#984E">4Dhello wor1<1"sp ansty="le--0:#C792EA;--1:#8844">AB0replaceA5<3(sp ansty="le--0:#D9F5DD;--1:#1111">1<1/sp ansty="le--0:#5CA7E4;--1:#3A68">81<1/sp ansty="le--0:#D6DEEB;--1:#403F">53<, sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">41<1"sp ansty="le--0:#D6DEEB;--1:#403F">53<);d ivclassNa="meco"><);d>AEconsB0teAE <= sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4Dexamp1<1"sp ansty="le--0:#D6DEEB;--1:#403F">5<3;d ivclassNa="meec-li">53teAB0matchA5<3(sp ansty="le--0:#7FDBCA;--1:#096E">72n5<3 sp ansty="le--0:#82AAFF;--1:#3B61">B0RegE5<3(sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">41<1"sp ansty="le--0:#D6DEEB;--1:#403F">53)<);d ivclassNa="meco"><);d>
1<111" spans="tyle--0:#ECC48D;--1:#98">4E4Dhello w1<111" spans="tyle--0:#C792EA;--1:#88">4<4AE. spans="tyle--0:#82AAFF;--1:#3B">61B0matc31<111/ spans="tyle--0:#5CA7E4;--1:#3A">6<88Fo spans="tyle--0:#D9F5DD;--1:#11">1<111/ spans="tyle--0:#5CA7E4;--1:#3A">6<88Fg spans="tyle--0:#D6DEEB;--1:#40">3F<53) ;divclass="Name"><;di vdivclass="Nameexpressive-">1<111" spans="tyle--0:#ECC48D;--1:#98">4E4Dhello w1<111" spans="tyle--0:#C792EA;--1:#88">4<4AE. spans="tyle--0:#82AAFF;--1:#3B">61B0replac31<111/ spans="tyle--0:#5CA7E4;--1:#3A">6<88Fo spans="tyle--0:#D9F5DD;--1:#11">1<111/ spans="tyle--0:#5CA7E4;--1:#3A">6<88Fg spans="tyle--0:#D6DEEB;--1:#40">3F<53, spans="tyle--0:#D9F5DD;--1:#11">1<111" spans="tyle--0:#ECC48D;--1:#98">41<111" spans="tyle--0:#D6DEEB;--1:#40">3F<53) ;divclass="Name"><0")><;di vdivclass="Nameexpressive-">44AEco61B044A1<111" spans="tyle--0:#ECC48D;--1:#98">4E4Dexa1<111" spans="tyle--0:#D6DEEB;--1:#40">33F534<4AE. spans="tyle--0:#82AAFF;--1:#3B">61B0matc36E7<2new spans="tyle--0:#D6DEEB;--1:#40">361B0Re31<111" spans="tyle--0:#ECC48D;--1:#98">41<111" spans="tyle--0:#D6DEEB;--1:#40">3F<53, spans="tyle--0:#D9F5DD;--1:#11">1<111" spans="tyle--0:#ECC48D;--1:#98">41<111" spans="tyle--0:#D6DEEB;--1:#40">3F5<3)) ;divclass="Name"><"))><;di vdivclass="Nameexpressive-">1<111" spans="tyle--0:#ECC48D;--1:#98">4E4Dhello w1<111" spans="tyle--0:#C792EA;--1:#88">4<4AE. spans="tyle--0:#82AAFF;--1:#3B">61B0replac31<111" spans="tyle--0:#ECC48D;--1:#98">41<111" spans="tyle--0:#D6DEEB;--1:#40">3F<53, spans="tyle--0:#D9F5DD;--1:#11">1<111" spans="tyle--0:#ECC48D;--1:#98">41<111" spans="tyle--0:#D6DEEB;--1:#40">3F<53) ;divclass="Name"><0")>

This rule is not configurable.

If you’re transpiling to an environment without matchAll() or replaceAll() support and have polyfills that don’t enforce the global flag requirement, you might want to disable this rule.