Description
Those methods return identical result for regexes without the g
flag.
From String#match
on MDN:
If the regular expression does not include the g flag, returns the same result as RegExp.exec().
I would like to enforce the use of RegExp#exec
instead String#match
for consistency when there's no g
flag in the regex, and because it's faster:
RegExp.prototype.exec
is a lot faster thanString.prototype.match
, but that’s because they are not exactly the same thing, they are different, their difference is out of this article’s scope, see this question: Stack Overflow.
This rule was originally proposed for inclusion in ESLint, but it was eventually declined for ambiguity reasons because of lack type knowledge. Lack of type knowledge is luckily not a problem here.