Simplify Multiple for each

How to use a single loop for all matches variable to iterate

Hi @AbarnaKalaiselvam

You won’t be able to use single for each activity for all the Matches variables. You need to use For each for dach variable you create in Find Matching Patterns.

You can try this:
Create an list variable of type System.Collections.Generic.List(IEnumerable(System.Text.RegularExpressions.Match))
You can append the output of Find Matching Patterns to list using Append Items to Vollections Activity.
Then use For each to iterate through list.

Hope you helps!!

What do you have in Find Matching Patterns? Possibly you could store the info for those activities in an array, datatable, etc, and loop over that - making the Find Matching Patterns dynamic.

Hello @AbarnaKalaiselvam it is difficult to use one single for each loop , tho you can avoid large code by using Linq code .

it depends on the details and also on what all regex patterns are trying to catch.

In some scenarios named groups did help to grab/collect different patterns in one go and then split it again into the different sets

1 Like

Hello @AbarnaKalaiselvam

Further to what @ppr said,

It depends on what you are matching. You could merge multiple Regex patterns into one to simplify. You could use Groups to match multiple items with one patten: (see below)

If you are doing the same thing in every “for each”, you create an array of Matches results and use a nested For Each at the end?



1 Like

For an illustration about using group names have a look here