Regex to extract value between 2 strings if a string exists multiple times

Hello,

I need to extract the value between 2 fixed strings, but the problem si one of them may appear multiple times.

“RING” is the word that may appear multiple times and “Ending” is the fixed string.

For example, this is my text:

RING
confidential 123
200 is the price
RING
$2000
RING
I want to buy something else
Right now

Ending

I need that the value extracted to be: “I want to buy something else Right now”

Thanks in advance!

hi @darie.leolea

Use the below regex expression:

(?<=RING\s*.*\d+\s*RING)([\s\S]*?)(?=\s*Ending)

Regards

Hi @darie.leolea

xaml:
Sequence15.xaml (7.8 KB)

Regards

Hello @darie.leolea

Try this Regex pattern - note your target text is the 1st Regex Group. Not the full match.

Let your input text be ‘yourStr’ and then use an Assign activity like this:
Left:
Str_Result

Right:
System.Text.RegularExpressions.Regex.Match(yourStr, “RING[\s\S]+RING([\s\S]+(?=Ending))”).Groups(1).ToString

You can learn Regex using my Megapost

Cheers

Steve

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