Skip to content

Commit b85261c

Browse files
authored
docs(eslint-plugin): update justification for prefer-regexp-exec (typescript-eslint#3392)
1 parent df7a0d6 commit b85261c

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

packages/eslint-plugin/docs/rules/prefer-regexp-exec.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
# Enforce that `RegExp#exec` is used instead of `String#match` if no global flag is provided (`prefer-regexp-exec`)
22

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.
44

55
## Rule Details
66

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.
88

99
From [`String#match` on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match):
1010

1111
> If the regular expression does not include the g flag, returns the same result as `RegExp.exec()`.
1212
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.
1614

1715
Examples of **incorrect** code for this rule:
1816

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy