Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Rule proposal: Prefer RegExp#exec() over String#match() #283

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sindresorhus opened this issue Feb 14, 2019 · 1 comment · Fixed by #305
Closed

Rule proposal: Prefer RegExp#exec() over String#match() #283

sindresorhus opened this issue Feb 14, 2019 · 1 comment · Fixed by #305
Labels
enhancement: new plugin rule New rule request for eslint-plugin has pr there is a PR raised to close this package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@sindresorhus
Copy link

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 than String.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.

@sindresorhus sindresorhus added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look labels Feb 14, 2019
@j-f1 j-f1 added enhancement: new plugin rule New rule request for eslint-plugin and removed triage Waiting for team members to take a look labels Feb 14, 2019
@ldrick
Copy link
Contributor

ldrick commented Feb 19, 2019

I'd love to take this one :-)

@bradzacher bradzacher added the has pr there is a PR raised to close this label Apr 25, 2019
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement: new plugin rule New rule request for eslint-plugin has pr there is a PR raised to close this package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants