You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- If you only care whether the regex matches a string, but not what is actually being matched, use {{jsxref("RegExp.prototype.test()")}} instead.
- If you are finding all occurrences of a global regex and you don't care about information like capturing groups, use {{jsxref("String.prototype.match()")}} instead. In addition, {{jsxref("String.prototype.matchAll()")}} helps to simplify matching multiple parts of a string (with capture groups) by allowing you to iterate over the matches.
- If you are executing a match to find its index position in the string, use the {{jsxref("String.prototype.search()")}} method instead.
Can a bullet point to be added to that explains when you should use exec? In other words, what can exec do that's unique?
What did you expect to see?
n/a
Do you have any supporting links, references, or citations?
No response
Do you have anything more you want to share?
No response
The text was updated successfully, but these errors were encountered:
Calling RegExp.exec is like calling Generator.next. You are just manually stepping through the process. There are valid use cases for it, especially if you want some fancy stepping patterns like "process one match, ignore one match", or "advance 5 characters after every match". I could add an example, but I think it's more natural to say "these are use cases you can avoid using exec for" and then you can decide whether your use case is one of them (99% of the time it should be), or not.
MDN URL
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec#description
What specific section or headline is this issue about?
Description
What information was incorrect, unhelpful, or incomplete?
This list is really helpful but it only explains when you should not use
exec
.content/files/en-us/web/javascript/reference/global_objects/regexp/exec/index.md
Lines 51 to 53 in fceea99
Can a bullet point to be added to that explains when you should use
exec
? In other words, what canexec
do that's unique?What did you expect to see?
n/a
Do you have any supporting links, references, or citations?
No response
Do you have anything more you want to share?
No response
The text was updated successfully, but these errors were encountered: