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.

"hello world".matchAll(/o/);
"hello world".replaceAll(/o/, "0");
const text = "example";
text.matchAll(new RegExp("e"));

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.

Made with ❤️‍🔥 in Boston by Josh Goldberg and contributors.