Open oleedd opened 2 months ago
"caratraany".match(/\wa\w/og)
// "car", "rat", "raa", "aan" ("o" for overlapped results)
That's an example of its behavior. What about use cases, explaining when this would actually be useful?
It's not that hard to get this behavior already with custom code that uses a loop and sets lastIndex to the character after the last match, whenever a match is found. So the question is what would justify building this capability into the language. (My personal interest is as an author of regex libraries where such a capability could be added if it were actually substantially useful.)
It is to find results independent of each other. For example, finding words inside a word.
Some regex engines support this. So it is not a new idea.
It would be much better to have a flag instead of writing code. And lastIndex
is not available for match
, which is mainly used.
@rbuckton New feature suggestion.
What are some example use cases?