- group_me is the string to split into groups
- group_by is the regular expression to group by
This function finds all (non-overlapping) matches of the regular expression group_by within the string group_me. A 2-dimensional array of matching strings is returned. The first index is the number of the match, starting with 0 for the first match. The second index is the number of the group within each match, with exactly the same meaning as the 2nd parameter to group(): element 0 is the entire text matched by the regular expression, element 1 is the text matched by the first set of grouping parentheses within the expression, element 2 is the second set of grouping parentheses, and so on.
In this example, the regex tries to match a number followed by a space followed by a word. The number and the word are placed into groups.
The first match was "134 Muscle", the first group was "134" and the second group was "Muscle". The resulting output is:
group_string exists for convenience purposes, it doesn't extend ash's capabilities any more so than what is already possible with create_matcher, the following is functionality equivalent, albeit uglier:
The output is the same as before. To better understand what's going on, try removing the parenthesis from the regular expression
The resulting output is:As you can see, all group_string does is loop the regular expression populating a map with the group results along the way. The first int is the loop index while the second int is the group index with index 0 representing the full match exactly how group works.