Why is this an issue?

String.match() behaves the same way as RegExp.exec() when the regular expression does not include the global flag g. While they work the same, RegExp.exec() can be slightly faster than String.match(). Therefore, it should be preferred for better performance.

The rule reports an issue on a call to String.match() whenever it can be replaced with semantically equivalent RegExp.exec().

How to fix it

Rewrite the pattern matching from string.match(regex) to regex.exec(string).

Code examples

Noncompliant code example

'foo'.match(/bar/);

Compliant solution

/bar/.exec('foo');

Resources

Documentation