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()
.
'foo'.match(/bar/);
Rewrite the pattern matching from string.match(regex)
to regex.exec(string)
.
/bar/.exec('foo');