Skip to content

regexExecutors

Reports String.prototype.match calls that can be replaced with RegExp.prototype.exec.

✅ This rule is included in the ts stylisticStrict presets.

Reports calls to String.prototype.match() that should use RegExp.prototype.exec() instead. When a regular expression does not have the global flag (g), both methods behave identically, but exec() is clearer in intent and may be slightly faster.

const result = "something".match(/thing/);
const text = "something";
const result = text.match(/pattern/);
const result = "something".match(new RegExp("thing"));

Using the global flag with match() is valid because it returns all matches:

const allMatches = "one two three".match(/\w+/g);

This rule is not configurable.

If you prefer consistent use of String.prototype.match() regardless of whether the global flag is present, you may disable this rule.

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