For each Regex match

So for each substring in lengthy text, if I want to get all matches I am currently doing for each substring, search text using a regular expression to grab my capture groups and then searching and replacing the big text with the full match and replacing it with nothing (deleting it) to prevent KM from grabbing the same text.

Is there an easier, more full proof way to do this? I am having issues with it consistently working for scraping HTML.

How do you guys grab all matches of a regex and harvest those matches?

Hi @Byrein,

You may find this post helpful:

If I understand you correctly, this should NOT be necessary.

When you use the For Each action with a collection of Substrings In collection, KM will step through all RegEx matches in the full text, without repeating any of them. IOW, the first loop of the For Each will find the first match, and then the second loop will find the second match.
The For Each loop variable will contain the full match, which you can then use in a Search using Regular Expression action.

I hope that makes sense. If not, feel free to ask further questions.

1 Like

Makes total sense... I don't know why i was thinking of for each substring as a counter opposed to grabbing each substring as it cycles through.. The article that @martin posted did help a lot though.

Just needed some perspective, thank you!

1 Like