MACRO: Get List of RegEx Capture Group of Multiple Matches

Thanks @JMichaelTX.

This is how I understand it:
Let say, a string "str" contains "apple pear apple orange".
we use for each to search "apple".

For each "Var", substring: "apple", matching in "str".

The first loop:

"Var" = "apple" (the FIRST MATCH, i.e., the first word "apple" in "str")
If you repeat the search variable using RegEx "apple", 
it searches "apple" in "Var", which will return "apple". 
It is NOT the FIRST MATCH, it is the variable "Var" itself, 
because the variable "Var" in the first loop is already the FIRST MATCH.

The second loop:

Now, "Var" = "apple" (the SECOND MATCH, i.e., the third word "apple" in "str")
This time, again, the search variable using RegEx "apple" searches "apple" in "Var",
 which will return "apple".

What I'm trying is say is: We can use "MatchString" (in your example) directly. We do not need another RegEx search (with the same RegEx pattern) in it.

If you want to save the RegEx search result in the screenshot below in another variable. You can simply use "Set variable" VarName to "MatchString". It will return the same result as you use the RegEx search in the screenshot below. That is why I said, this action is redundant.
image

Hello @JMichaelTX,

I apologize. I just realized that I misunderstood your example.

If the variable were put in the "All" field, the result would be the same. It would make the action redundant. This is where my misunderstanding came from.
Thanks for your patience.

1 Like

No problem. When I first started using RegEx in KM I had similar challenges understand how and why to use it. Each app handles processing of multiple matches differently.

First I am a beginner so you have to bear with me if it is completely obvious. I am trying to make such that I can make playlists from the radio web page and I have to pull the number and artist out they are in the line where there is an @ sign where the number is the first and the artist the next. So first I want to catch all lines with @ characters with Regex and there I came across the example here but I can not get it to work with my regex as I have checked on regex101.com and in bbedit where it works. What am I doing wrong and is there anyone who can help? Thanks to JMichaelTX for the basic macro and your always great answersGet a playlist  from selection Get a playlist from selection.kmmacros (19.1 KB)