Clear Ienumerable<Match> in a for each loop


i have an issue - i am using a for each loop in order to extract with Regex some information from different invoices.

And i have an issue with a loop, because if the information doesn’t exist in that certain invoice, it will write the last value it found in a previous invoice. I can’t figure out how to reset the variable before the loop.

My process looks something like this:

Any hint, advice, suggestion is more than welcomed.



Can you refer to the below thread? Hope it helps.

i tried it and it doesn’t work for me :frowning:

Hi @Cristian_Ionita,

Approach 1:
So you could do the check in an earlier If condition match.count>0 then go into the for each loop. This way you can remove the Then branch and keep it empty as this condition will already have been checked by the outer If condition.

Approach 2:
Referring the solution from :

Basically, this flow will ensure that when there are no matches, the for loop is never called and the Matches variable is reset using {} or Nothing

Here is a sample file: MatchesSetToNull.xaml (12.7 KB)

please share directly what was done, what was not working


you can re-initialize the variable before foreach as
variable = new List(of system.text.RegularExpressions.Match)

Just add an assign activity, re-initializing the variable, which clears variable.


i’m doing something wrong, i think that in the writing part of the process or something.

could someone have the time to double check my process? because i can’t figure it out for the death of me.

invoice info.xaml (22.6 KB)

A nudge would help a lot.


Hi @Cristian_Ionita,

I do know what dependency you have in your project so I cannot test the workflow for you.

I notice that you have used a Object type for For Each —>Match
I suggest you convert it to the System.Text.RegularExpression.Match type

Finally row.item("Value") / row("Value") can be assigned to the item.ToString in match. Where item.ToString is the extracted string from your regex expression.

Finally when that row is processed you set the match variable to either {}, Nothing, or New List(of System.Text.RegularExpressions.Match)

Also kindly check the alternative suggestion I provided in the post above. That way you will do the data validation for “match” variable. If the matches is null you avoid the For Each —>Match.

bless you :grin: added also a reset to the column I was writing and it works

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