Returning Multiple Regex Results in a Datatable

Hi, i am attempting to write a sequence to extract certain data from PDF (using Regex), write the results to a datatable and then subsequently to excel.

However, i am only able to write the first match result to excel. My PDF can contain multiple matches (multiple matches for payment modes and total amounts). I wish to populate these multiple matches to excel and not the first match only.

I would need the other matches to be included in the excel sheet too.

Please help. My workflow looks like this.

My input PDF and output Excel document is as such

You can rewrite your code a bit to find all the Payment Mode and Total Amount matches separately, then you can zip them up into multiple data rows afterwards. I’ve attached a sequence that will find the matches and then add multiple rows into a DataTable.

You’ll need to copy paste it into your code and and input your Regex, etc. I also haven’t tested it because I don’t have your code. Let me know how it goes.
FindAllMatches.xaml (8.9 KB)

1 Like

Hi @leongy
This is great use case you have shared here.
when you use ienMatch(0).value it restricts the results to first item only.
try using a loop for all item in ienMatch variable, ienMatch(index).value to access all extracted results.

Hope this was helpful.
cheers

Hi Karan, thanks for explaining. I’m rather new to UiPath.

Could you further explain where i should place the For Each loop? Further to that, you mentioned to use ienMatch(index).value. How do i use this? Would appreciate if you could share your knowledge.

Hey @leongy
I tried to design something just like you have,
i have used a string I/P and made regex to extract data after the keyword “Number”. it has multiple occurrence.

The solution with for loop should look like this -

stored it into a string and logged for reference.
You can add to excel file as per requirements.