File tree 1 file changed +3
-5
lines changed
packages/eslint-plugin/docs/rules
1 file changed +3
-5
lines changed Original file line number Diff line number Diff line change 1
1
# Enforce that ` RegExp#exec ` is used instead of ` String#match ` if no global flag is provided (` prefer-regexp-exec ` )
2
2
3
- ` RegExp#exec ` is faster than ` String#match ` and both work the same when not using the ` / g` flag.
3
+ 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 .
4
4
5
5
## Rule Details
6
6
7
- This rule is aimed at enforcing the more performant way of applying regular expressions on strings.
7
+ This rule is aimed at enforcing a consistent way to apply regular expressions to strings.
8
8
9
9
From [ ` String#match ` on MDN] ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match ) :
10
10
11
11
> If the regular expression does not include the g flag, returns the same result as ` RegExp.exec() ` .
12
12
13
- From [ Stack Overflow] ( https://stackoverflow.com/questions/9214754/what-is-the-difference-between-regexp-s-exec-function-and-string-s-match-fun )
14
-
15
- > ` 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.
13
+ ` RegExp#exec ` may also be slightly faster than ` String#match ` ; this is the reason to choose it as the preferred usage.
16
14
17
15
Examples of ** incorrect** code for this rule:
18
16
You can’t perform that action at this time.
0 commit comments