No, you
are referring to other languages.
/.../g is a JavaScript construct. Only the
... part is regex.
The g flag causes
match to return only the overall matches. To get all matches including captured subpatterns, there is
matchAll, which
requires the g flag. It's actually a relatively new function that doesn't exist in Internet Explorer. Apparently before it was added, the way to get all matches with captured subpatterns was to
call regexp.exec() in a loop.
The flag does not affect the matching behaviour of the regex; it only affects how specific JavaScript functions utilize the regex.
Also, the JavaScript RegExp object is not a regular expression or regex. It is an object which encapsulates a regex pattern with a set of methods for applying it in different ways, like putting together a regex string, RegExMatch, RegExReplace and a hypothetical future match-all function. You could create such an object yourself, although it wouldn't be as efficient as a built-in object.
The RegExMatch function or object could be "overloaded" with match-all functionality, but there are a number of reasons I do not think it would be appropriate:
- The OutputVar parameter is what it says, an output parameter. If it differentiated by whether the variable already contains a match object, you would have to explicitly reset the variable between runs, if you're using the RegExMatch loop inside a larger loop.
- It is inefficient to pass the haystack and needle again if they are stored in the match object (although I think only the necessary substring is stored in the match object at the moment).
- It doesn't make sense to pass the haystack and needle again if the matching state (i.e. last match index) relies on the specific haystack or needle. What is the function supposed to do if the parameters have been changed?
- For using the match object itself to get repeated matches, you would need to first call RegExMatch once to get the match object.
In JavaScript, the RegExp object represents the regex itself, not the matches.
For repeated calls, it looks like you pass the haystack in repeatedly. Because the RegExp object represents the pattern and not a match, it does not store the haystack. I suppose the only "state" it has aside from the pattern itself is a single integer,
lastIndex.
I agree that more convenient RegEx functions would be useful, but there are many such features that could (and will) be implemented, and usually only one developer (sometimes zero) working on AutoHotkey. Currently my priority is on making v2 more accessible to users, although if I'm here writing posts, I'm probably procrastinating...