How to extract all regex matches splitted by Groups to a datatable

Hi,

I want to extract all matches to a datatable, separated in columns by Groups.

DT would be something like this:

A ---------- B
100-------1643
101--------
102--------
103--------23457
104--------235
105--------

Can help me please?

I can’t find a way to do this…

Thanks!!

1 Like

Can you provide your input to this problem so we can try identify how to assist you :slight_smile:

1 Like

Hello,
I copy a fragment down!

Where 00xxx its group 1 (always existe) and the ammount is group 2.

My pattern:

“(00\d{3})\s(\ - * \d * \ ,* \ d *)”

Desarrollo (N) 00103 27456,04
Concesiones (N) 00104
Patentes, licencias, marcas y similares (N) 00105
Fondo de comercio (N, A, P) 00106 1325,03
Aplicaciones informáticas (N) 00107 8757,92
Investigación (N) 00108
Propiedad intelectual (N) 00700
Otro inmovilizado intangible (N) 00109 -5643,01
Resto (A, P) 00110

1 Like

@Japp @Japp Use following regex (00\d{3})\s([\d,-]+) to extract String together and group1, group2.
System.Text.RegularExpressions.Regex.Matches(InputVariable,“(00\d{3})\s([\d,-]+)”). It will give you a collection of matches. Use For Each and Add Data row to insert the group values into DataTable item.Groups(1) and item.Groups(2)

1 Like

Hi, thanks for answer!

So my sequence, could be…

Create datatable

Read PDF

Matches (Result =“resultmatches”) pattern ((00\d{3})\s([\d,-]+))

For each (item in resultmatches)
Add row to datatable

System.Text.RegularExpressions.Regex.Matches(InputVariable,“(00\d{3})\s([\d,-]+)”) and item.groups(1)

When i put that i have a error… Where i put this?

1 Like

@Japp group1 value will be item.groups(1).value and similarly
item.groups(2).value

3 Likes

Thanks! Works now!!!

2 Likes

Hi again!!

Now im triying to extract the matches of each file in diferents columns, for example…

A-B-C-D-E-F
1-2-1-2-1-2
1-2-1-2-1-2
1-2-1-2-1-2

Im using for each file in directory.getfiles(“path”) but the extraction give me all the extract data of each file in the same column:

A-B
1-2 (File 1)
1-2 (File 1)
1-2 (File 1)
1-2 (File 2)
1-2 (File 2)
1-2 (File 2)
1-2 (File 3)
1-2 (File 3)
1-2 (File 3)

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