Having to do a Search Using Regular Expression action to extract each capture group within a For Each RegEx Match action seems a little over-complicated and redundant; especially since you have to use the same RegEx pattern in both. It also requires two variables (MatchString and CaptureString).
How about including a new, consolidated option to the For Each... action that allows us to provide a RegEx pattern and it iterates over each resulting capture group?
For Each [CapturedString] in these collections:
.... The capture group [RegEx pattern]
......... ignoring case in
............ Variable [SourceString]
It is irritating that you have to repeat the regex, but it is problematic to do otherwise.
It would be rare that you want to iterate over the different capture groups, typically each part would mean something different. So you really want to capture all the capture groups to variables like the Search using Regular Expression action does.
And it needs the regex as well to know how many fields there are so it can allocate variables to them. And I don't think it would want to use some sort of spooky reference to the For Each action.
Nor do I really want to violate the way collections work by having it assign other variables as part of its behaviour.
So unless I come up with some other way that I like better, you are stuck doing a For Each and then a Search using Regular Expression.
It may not be a typical use-case and I may not be doing this in the most efficient way possible, but here's my scenario:
I need to control an app that dynamically builds a menu tree which mimics a multi-level folder structure in the file system.
Folders <=> sub-menus
Files <=> menu items.
(Files can reside at any folder level so branches vary in length.)
Since the menu is fluid, I can't use static coordinates to get the mouse pointer to a given menu item. Luckily, the menu is displayed alphabetically, so I can use the index to each folder/file as a Y-coordinate multiplier and know how far down to move the mouse to get to the next sub-menu..
At program launch, I traverse the current folder structure and build a breadcrumb path to each file. I store the filename/breadcrumb pairs in a JSON variable.
Breadcrumbs are strings with colon-separated indices to each parent menu.
TriggerValue is used to supply the macro with the name of the menu item to be clicked.
I use For Each RegEx Match to parse the breadcrumb. Each capture group contains an index. The loop grabs each index, computes coordinates, moves/clicks mouse until it reaches the desired menu item.
I'm sort of following you (except I'm not entirely clear on the JSON part) but I don't really see where the existing solution (with a For Each action followed by a Search Using RegEx action) does not get the job done…?