Hey JM,
Good communication always demands some level of precision, and since regular expressions are very technical the necessary level of precision goes up when describing them.
A match.
A group.
A capture-group.
Are all considered to be separate entities.
(the\w+) # A capture-group.
(?:the\w+) # A non-capturing group.
So while we might talk about grouping part of the pattern, we should always distinguish that from a capture-group.
Match is entire match ā and as youāve seen the āgā switch may produce multiple matches.
You can easily get tripped up in one of these online analyzers that emulate programming language level /search/replace/ code.
Without understanding how all the separators and switches work itās easy to get confused.
Many people mistakenly believe the forward slashes are part of the pattern, so I donāt advise their use except as part of real code snippets.
$myStrVar =~ s/\w/ā¢/g # Canonical Perl
$myStrVar =~ s!\w!ā¢!g # My preference for pattern separation characters ('!').
Unless Iām talking to someone I know is versed in the syntax Iām using I find it more effective to explicitly separate search (or find) pattern, replace pattern, and switches.
Search Pattern:
<my search pattern>
Replace Pattern:
<my replace pattern>
Switches:
msixg
And when youāre talking about a GUI regex environment itās usually more effective to present switches in-line in the pattern:
(?imx)<more pattern> # ON
(?-imx)<more pattern> # OFF
(?s-i)[a-z[:punct:][:blank:]]+ # MIXED
Another pitfall of regular expression analyzers is that you can get something working without understanding why it works. (Often true of Life in general of course.)
Using good vocabulary even when talking to oneself about RegEx helps us to understand them better. After 20 some-odd years of use and study I continue to learn new stuff, and Iāve found the need to tighten up my own vocabulary.
Hopefully this is more informative than pedantic .
-Chris