Data extraction from given string pattern

Hi Team,

I want to extract data from the below string. As u can see in the pattern first line is product name. Second line is number of piece and after that dimensions of the product. So I want to extract number between brackets, Cut to size pieces and dimensions for each product.

2 x Hot Rolled Steel Rectangle Bar (10050300) = Call for Price
• # of Cut to Size Pieces - 2
• Length - 47"

1 x Hot Rolled Steel Sheet & Plate (HRP016408) = Call for Price
• # of Cut to Size Pieces - 1
• Length - 60"
• Width - 4"

2 x 5052 Aluminum Sheet & Plate (52SH025412) = Call for Price
• # of Cut to Size Pieces - 2
• Length - 30"
• Width - 4"

Hi,

Hope the following helps you.

Number between brackets

System.Text.RegularExpressions.Regex.Match(yourString,"(?<=\()\w+?(?=\))").Value

Cut to size pieces

System.Text.RegularExpressions.Regex.Match(yourString,"(?<=# of Cut to Size Pieces -\s*).*").Value

Length

System.Text.RegularExpressions.Regex.Match(yourString,"(?<=Length -\s*).*").Value

Width

System.Text.RegularExpressions.Regex.Match(yourString,"(?<=Width -\s*).*").Value

Regards,

Thanks for the reply. I need to get each product detail. So basically first i need to get each product into string. So please help me in splitting on the basis of empty line if possible than i will use the the regex u have mentioned.

2 x Hot Rolled Steel Rectangle Bar (10050300) = Call for Price
• # of Cut to Size Pieces - 2
• Length - 47"

1 x Hot Rolled Steel Sheet & Plate (HRP016408) = Call for Price
• # of Cut to Size Pieces - 1
• Length - 60"
• Width - 4

Hi,

How about using Regex.Split as the following?

products = System.Text.RegularExpressions.Regex.Split(strData,“\r?\n\r?\n”)

Sample20220513-1a.zip (2.8 KB)

Regards,

1 Like

An alternative solution with groups:

\d x (?<product>.+) = Call for Price\r?\n• # of Cut to Size Pieces - (?<pieces>\d+)\r?\n• Length - (?<length>\d+")(\r?\n• Width - (?<width>\d+"))?

Use the pattern with the Matches activity. Loop through the matches and access the fields:

m.Groups("product").ToString
m.Groups("pieces").ToString
m.Groups("length").ToString
m.Groups("width").ToString

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