diff --git a/packages/eslint-plugin/docs/rules/prefer-regexp-exec.md b/packages/eslint-plugin/docs/rules/prefer-regexp-exec.md index 4640d35a98e..3f3d149a7f7 100644 --- a/packages/eslint-plugin/docs/rules/prefer-regexp-exec.md +++ b/packages/eslint-plugin/docs/rules/prefer-regexp-exec.md @@ -1,18 +1,16 @@ # Enforce that `RegExp#exec` is used instead of `String#match` if no global flag is provided (`prefer-regexp-exec`) -`RegExp#exec` is faster than `String#match` and both work the same when not using the `/g` flag. +As `String#match` is defined to be the same as `RegExp#exec` when the regular expression does not include the `g` flag, prefer a consistent usage. ## Rule Details -This rule is aimed at enforcing the more performant way of applying regular expressions on strings. +This rule is aimed at enforcing a consistent way to apply regular expressions to strings. From [`String#match` on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match): > If the regular expression does not include the g flag, returns the same result as `RegExp.exec()`. -From [Stack Overflow](https://stackoverflow.com/questions/9214754/what-is-the-difference-between-regexp-s-exec-function-and-string-s-match-fun) - -> `RegExp.prototype.exec` is a lot faster than `String.prototype.match`, but that’s because they are not exactly the same thing, they are different. +`RegExp#exec` may also be slightly faster than `String#match`; this is the reason to choose it as the preferred usage. Examples of **incorrect** code for this rule: