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".
String.matchAll(regexp: RegExp): RegExpStringIterator<RegExpExecArray>

Matches a string with a regular expression, and returns an iterable of matches containing the results of that search.

@paramregexp A variable name or string literal containing the regular expression pattern and flags.

matchAll
(/o/);
"hello world".
String.replaceAll(searchValue: string | RegExp, replaceValue: string): string (+1 overload)

Replace all instances of a substring in a string, using a regular expression or search string.

@paramsearchValue A string to search for.

@paramreplaceValue A string containing the text to replace for every successful match of searchValue in this string.

replaceAll
(/o/, "0");
const
const text: "example"
text
= "example";
const text: "example"
text
.
String.matchAll(regexp: RegExp): RegExpStringIterator<RegExpExecArray>

Matches a string with a regular expression, and returns an iterable of matches containing the results of that search.

@paramregexp A variable name or string literal containing the regular expression pattern and flags.

matchAll
(new
var RegExp: RegExpConstructor
new (pattern: RegExp | string, flags?: string) => RegExp (+2 overloads)
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 ❤️‍🔥 around the world by the Flint team and contributors.