{"action":"created","issue":{"url":"https://api.github.com/repos/eslint/eslint/issues/3477","labels_url":"https://api.github.com/repos/eslint/eslint/issues/3477/labels{/name}","comments_url":"https://api.github.com/repos/eslint/eslint/issues/3477/comments","events_url":"https://api.github.com/repos/eslint/eslint/issues/3477/events","html_url":"https://github.com/eslint/eslint/issues/3477","id":102360660,"number":3477,"title":"Rule proposal: Prefer `RegExp#exec` over `String#match`","user":{"login":"sindresorhus","id":170270,"avatar_url":"https://avatars.githubusercontent.com/u/170270?v=3","gravatar_id":"","url":"https://api.github.com/users/sindresorhus","html_url":"https://github.com/sindresorhus","followers_url":"https://api.github.com/users/sindresorhus/followers","following_url":"https://api.github.com/users/sindresorhus/following{/other_user}","gists_url":"https://api.github.com/users/sindresorhus/gists{/gist_id}","starred_url":"https://api.github.com/users/sindresorhus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sindresorhus/subscriptions","organizations_url":"https://api.github.com/users/sindresorhus/orgs","repos_url":"https://api.github.com/users/sindresorhus/repos","events_url":"https://api.github.com/users/sindresorhus/events{/privacy}","received_events_url":"https://api.github.com/users/sindresorhus/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/eslint/eslint/labels/triage","name":"triage","color":"cc317c"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-08-21T11:47:23Z","updated_at":"2015-09-05T07:46:13Z","closed_at":null,"body":"## Problem\r\n\r\nThey return identical result for regexes without the `g` flag. From [`String#match` on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match):\r\n\r\n> If the regular expression does not include the g flag, returns the same result as RegExp.exec().\r\n\r\nI would like to enforce use of [`RegExp#exec`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec) instead [`String#match`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match) for consistency when there's no `g` flag in the regex.\r\n\r\n## Solution\r\n\r\nAdd a rule called `prefer-regexp-exec` that enforces the consistency if it encounters a `String#match` call with a regex that doesn't have a `g` (global) flag."},"comment":{"url":"https://api.github.com/repos/eslint/eslint/issues/comments/137925099","html_url":"https://github.com/eslint/eslint/issues/3477#issuecomment-137925099","issue_url":"https://api.github.com/repos/eslint/eslint/issues/3477","id":137925099,"user":{"login":"sindresorhus","id":170270,"avatar_url":"https://avatars.githubusercontent.com/u/170270?v=3","gravatar_id":"","url":"https://api.github.com/users/sindresorhus","html_url":"https://github.com/sindresorhus","followers_url":"https://api.github.com/users/sindresorhus/followers","following_url":"https://api.github.com/users/sindresorhus/following{/other_user}","gists_url":"https://api.github.com/users/sindresorhus/gists{/gist_id}","starred_url":"https://api.github.com/users/sindresorhus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sindresorhus/subscriptions","organizations_url":"https://api.github.com/users/sindresorhus/orgs","repos_url":"https://api.github.com/users/sindresorhus/repos","events_url":"https://api.github.com/users/sindresorhus/events{/privacy}","received_events_url":"https://api.github.com/users/sindresorhus/received_events","type":"User","site_admin":false},"created_at":"2015-09-05T07:46:13Z","updated_at":"2015-09-05T07:46:13Z","body":"Aren't all of the following rules just a matter of preference too? → http://eslint.org/docs/rules/#stylistic-issues\r\n\r\nI use ESLint not only to catch errors, but also to enforce consistency. I often see these two methods used   interchangeably, but I prefer using `RegExp#exec`, and want to enforce that style in my code. This request comes after having had to comment on two recent pull requests about switching to `RegExp#exec`. I think it should be in core as it's a very common thing to interchange, but very few actually realize those methods are interchangeable. A core rule would make people realize this and appreciate the consistency the rule enforces."}}