Regex Pattern to extract screen scrape results

I want to extract the information from the string below and insert the data into a data table.
I try to create the regex pattern, but because of the occurrence of the words Product Id, Quantity, Item is more than one so my regex will not work.
Can anyone help me how can I extract the information from the string using regex ?

String:

-----------------------------------------------------------------------------
Product ID : TXSKJI1123321
Quantity : 19
Item : Jeans
-----------------------------------------------------------------------------
NEXT ACTIONS
Increase stock for TXSKJI1123321 up to 100 units

-----------------------------------------------------------------------------
Product ID : AKSP2790173332
Quantity : 7
Item : Shirts
-----------------------------------------------------------------------------
NEXT ACTIONS
Increase stock for AKSP2790173332 up to 50 units

-----------------------------------------------------------------------------
Product ID: AKSP27901733789
Quantity : 2
Item : Vest
-----------------------------------------------------------------------------
NEXT ACTIONS
Increase stock for AKSP27901733789 up to 15 units

Data table should look like this:
image

Regex that I use but failed:
(?<=Product ID\s\S)(.|\n)*(?=Quantity )

Hi,

Can you try the following?

mc = System.Text.RegularExpressions.Regex.Matches(strData,"Product ID\s*:\s*(?<PRODUCTID>\w+)\s*Quantity\s*:\s*(?<QUANTITY>\w+)\s*Item\s*:\s*(?<ITEM>\w+)[\s\S]*?NEXT\s*ACTIONS\s*(?<NEXTACTIONS>.*)")

Sequence4.xaml (10.0 KB)

Note : If there are some whitespace in each record, it might be needed to modify pattern regarding \w+.

Regards,

I have tried to recreate the solutions you gave for my actual use case and it works.
Thank you for the help. Really appreciate it :slight_smile:

1 Like

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