IEnumerable <Regex Matches> to Datatable (best way to meaningfully extract data from multiple IEnumerables)?



I have a sequence where I am using ReadPDF and then the Matches activity with Regex to great success.

The output is coming out as ItemNamesRaw an IEnumberable variable for the first Matches activity and as QtyRaw which is an IEnumrable variable for the second Matches activity on the same PDF.

Currently I just have: For Each Item in the Variable converted to string and writing a line to be sure that they are all being read correctly.

I would like to have them append columns in an excel spreadsheet for inventory purposes, (all items to column A and all Qtys to Column B for example) but I’m having trouble figuring out how to convert the IEnumerable into a DataTable as that’s what is required to append a range.

1. Should I be aiming towards using Append Range to do this?

2. Is there a more meaningful and maybe flexible way to extract and collect the information within the IEnumerable so that I can access this information in the best way possible?

I don’t recall learning something specifically already that I can think of using, so maybe this is further ahead in the Academy than I am, (I’m about 25%) but even being pointed in the right direction would be great.

As always thanks for all the help on these forums, it’s always quick and concise to get an answer and I’m loving the community here.


Did you try ItemNamesRaw.CopyToDataTable? (you won’t get intellisense, but you should import System.Linq)

if you need to bifurcate your Item and Quantity, build a datatable and probably you can bifurcate by length (eg >5) or contains hyphen (-) then add to different A or Add to column B.

Will think of more options…


Where would I put “ItemNamesRaw.CopyToDataTable” ? …In an assign activity?

Also, what is System.Linq? and where would I use it?


Yes create a database variable and assign ItemNamesRaw.CopyToDataTable to that variable.

To Import System.Linq, after Variable,Arguements tabs you see Import Tab, in the search bar type System.Linq and add it to your project.


Getting this error when trying to use the .CopyToDataTable

It’s not popping up to autopopulate like commands usually do.


As I understand then, .Linq imported will give me more commands to use? Including .CopyToDataTable?

I imported the System.Linq and System.Linq.Expressions and I’m still getting that same error though.

Do I need to do anything else to be able to use those expressions?


Sorry I did not notice that your Inumerable is Regex Match type, it works only with DataRow type.I will give you another solution.


Thank you!
*Waits patiently


Your item and quantity are mapped? Or Random?


They are Mapped, corresponding to each other… Is that what you mean?


Yes sir.just a thought on what basis are you getting regex match? Can you concatenate item quantity at regex level itself?


Item: (?<=Article Number: ).{13}([^\n\r]*)
Qty: \d+(?= piece ).{1}

… Even if I get them both from regex and concatenate them, I’m still looking at how I’m going to get the data out of an IEnumerable of Regex though right?

If I got them into just one, concatenated… how would I get to that data? Isn’t it the same problem I’m having or could I do something else with that?


This should give an idea. Good luck.

matches.xaml (9.5 KB)

How to convert IEnumerable object to DataTable object?

That was exactly what was needed. :clap:

Thank you very much, I’ve got everything running correctly with my data.

It was very helpful for you to make a template for me, and I can understand the processes used now. Really great job and thanks again and kudos!!


Hey, I saw your solution and I am looking for something similar I think, but I don’t understand the file you send.

I use a matches activity with the following regex pattern: “\s[0-9]{23}\s”, to find all strings on a page that are 23 digits long. Now I want to filter the results so there is only unique results. I thought I’d do that by putting them in a data table or excel or something and then further filter, but I can’t figure out how to get the collection of matches into a data table/excel

Help would be much appreciated!
Thanks :slight_smile: