How to itterate over regex groups

Im currently trying to simply itterate over groups from a regex match but i cant get it to work. the Thing is it Needs to be generic. so the amount of groups in the match can change so it Needs to be done with some Kind of itteration and not with direct accessing the value.

The write line should eventualy be replaced with a string concatination.

Kind regards

Main.xaml (6.1 KB)

Hi @Roger.B,
Welcome to the Community!
Output of Regex Matches where your input string can have many groups can be used with index. In Your case “MyMatches(0).ToString”, “MyMatches(1).ToString” etc.

Hi @ Pablito

I tried your aproach with a while loop and an itterator variable, but i cant Access the any group except the (0) first one. when i inspect the iEnumerable variable then i also only see one item, am i doing something wrong with the matching?

Ahh sorry. I forgot that you are asking for group extraction and was thinking about match extraction.
In that way use this approach: “MyMatches(0).Groups(1).ToString”, “MyMatches(0).Groups(2).ToString” etc.
Remember that for groups indexing is starting from (1)… If you will use “MyMatches(0).Groups(0).ToString” it will return the same as “MyMatches(0).ToString” :wink:


alright it finaly works :smiley: thank you very much.

Main.xaml (7.0 KB)

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.