Text Extraction and Regex challenge

Hi,

I have an issue with regards to extraction information from text file and need help and idea.

I have input as below

Block 11 (Plot 461 - Plot462)= 12 units Block 14 (Plot 601 - Plot624)= 24 units
(Plot 476 - Plot487)= 12 units (Plot 626 - Plot649)= 24 units
Block 12 (Plot 501 - Plot 524)= 24 units Block 15 (Plot 651 - Plot 706) = 56 units

and expected output as

How can I extract those info by using Regex ? is that possible to used regex command in this situation.

Thank you

Hi @Abang_Jamuri_Abang_Shoker

Can you try this regex:

Block\s?(\d+)\s?(Plot\s?(\d+) - Plot\s?(\d+))\s?=\s?(\d+)\s?units

This expressions gives you all matches and groups. Then you can use the values.

Regards.

Hi tolga.kamci

thanks for the reply but could not get the value.

got the error

Hello @Abang_Jamuri_Abang_Shoker

can you try below. It is combination of LINQ and REgex
Use build datatable activity for generating dt_test

dt_test = (From match as System.Text.RegularExpressions.Match in System.Text.RegularExpressions.Regex.Matches(str_Input,"(Block [\d]+)\s\(Plot ([\d]+) \- Plot\s*(\d+)\)\s?=.+?(\d+)").Cast(of System.Text.RegularExpressions.Match) select x = dt_test.LoadDataRow({match.Groups(1).Value,match.Groups(2).Value,match.Groups(3).Value,match.Groups(4).Value},True)).CopyToDataTable

Hi AkshaySandhu,

got an error

My edited query

“(From match as System.Text.RegularExpressions.Match in System.Text.RegularExpressions.Regex.Matches(txtline,”(Block [\d]+)\s(Plot ([\d]+) - Plot\s*(\d+))\s?=.+?(\d+)“).Cast(of System.Text.RegularExpressions.Match) select x = dttable.LoadDataRow({match.Groups(1).Value,match.Groups(2).Value,match.Groups(3).Value,match.Groups(4).Value},True)).CopyToDataTable”

Not sure why I got the error

do not keep code in double quotes. Directly assign it to dt_test

Also try to copy the code from code block that I gave you…
if you face issue with double quotes (as I can see from error message), after pasting the code, replace all double quotes by type it manually.

here is xaml file, just incase if you face any issue
Generate_DataTable.xaml (7.7 KB)

1 Like

Thanks AkshaySandhu, manage to get the output…

1 Like

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