Extract string between two other repeating strings

I have to extract each string between 2 other strings which are “REASON FOR LEAVING” and “ABC COMPANY” but the thing giving me trouble is the 2 other strings repeat. I need to get each string between each repeating 2 strings. How can I accomplish this out of something like below?
SALARY

DUTIES

REASON FOR LEAVING

FROM (MM/DD/YY)

HOURS PER WEEK

SALARY

DUTIES

REASON FOR LEAVING

BECAUSE OF SOME TEST REASON
BECAUSE OF SOME TEST REASON ABC COMPANY HUMAN RESOURCES

EXAMINATION / EMPLOYMENT

SALARY

DUTIES

REASON FOR LEAVING
DIFFERENT TEST REASON

FROM (M/D/Y)

SALARY

DUTIES

REASON FOR LEAVING

ANOTHER TEST REASON
ANOTHER TEST REASON ABC COMPANY HUMAN RESOURCES

EXAMINATION / EMPLOYMENT

Welcome @Adrian_J to the UiPath Community :partying_face:

Thank you for the sample text.

Can you tell us/bold the expected output. What else is consistent about the text?

Cheers

Steve

Hi Steve, thanks for replying. The output I’m expecting is to add each string found to a List strExtract for later use as shown below:
strExtract1:
BECAUSE OF SOME TEST REASON
BECAUSE OF SOME TEST REASON

strExtract2:
ANOTHER TEST REASON
ANOTHER TEST REASON

Hey @Adrian_J

Thank you for the output. Take a look at this solution I have made. Main.xaml (11.3 KB)

image

You can preview the regex pattern here.

Check out my Regex MegaPost if you want to learn more.

Hopefully this helps

Cheers

Steve

Thank you so much for this regex help Steven. I couldn’t view the file you attached, it just wouldn’t open for some reason. But I will try to implement the regex from the link you attached and I’ll check out the MEGAPOST too and let you know how it works out for me.

Hey @Adrian_J

Okay, lets try another way :blush:

Option 1:
Watch this tutorial from Anders Jensen

Option 2: Follow my step by step instructions below

Step 1:
Get your variables into their string variables.

Step 2:
Insert a Matches / FInd Matching Patterns activity.

Step 3: Insert your variables from step 1 into the Properties of the Matches activity (top right). See image below.

Step 4: (See image below)
Click into the ‘Result’ field into the properties panel of the matches activity (see the red circle in the top right). Press ‘Ctrl + K’ can call it ‘Matches_Results’.

Step 5:
Insert a ‘For Each’ activity (Green circle).

Step 6:
Insert the variables ‘Matches_Results’ into the For each.

Step 7:
Insert a log message (Purple circle) with the text exactly
"Result: "+currentItem.ToString

Step 8:
Click run and it should work :slight_smile:

Hopefully combined you have something to help you out :blush:

Cheers

Steve

Thank you so much Steve. This is just what I was looking for!

1 Like

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