25 lines
991 B
Plaintext

== 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()`.
[source,javascript,diff-id=1,diff-type=noncompliant]
----
'foo'.match(/bar/);
----
Rewrite the pattern matching from `string.match(regex)` to `regex.exec(string)`.
[source,javascript,diff-id=1,diff-type=compliant]
----
/bar/.exec('foo');
----
== Resources
=== Documentation
* MDN web docs - https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Global_Objects/String/match[``++String.prototype.match()++``]
* MDN web docs - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec[``++RegExp.prototype.exec()++``]