Need to Extract a text between two labels and the two labels may repeat

Hi All,
Before creating this topic, I had searched in forum but unable to find the apt solution for my scenario.
I want to extract a text between two labels and the two labels may occur more than once in the notepad.
If the two labels repeats twice, then i need to get the text between two labels twice.
Can anyone please help me to find a solution for this scenario.

yah we can use REGEX onthis
–lets get the output from notepad with READ TEXT FILE activity as a string variable
named strinput
–now use a MATCHES activity where mention this expression “(?<=firstlabel).*(?=secondlabel)”)

and get the output with a variable named outmatches
–now use a FOR EACH activity where pass this variable as input and change the type argument as system.Text.RegularExpressions.Regex.Match
and inside the loop use writeline and mention like this item.ToString

Cheers @sanju_RPA

1 Like

Hi @Palaniyappan,
I had used the above regex expression “(?<=firstlabel).*(?=secondlabel)”), but it is throwing an error.
[Source: Matches

Message: parsing “(?<=firstlabel).*(?=secondlabel))” - Too many )'s.

Exception Type: System.ArgumentException]


Could you please check this issue.

@sanju_RPA,

Check the xaml, this may help you.
As of now it is working for two occurrences, if you need to more occurrences then have to increase the startIndex and endIndex value part’s +1 to +2 or some number you want.

ExtractStringBetweenTwoStrings.xaml (5.7 KB)

1 Like

Hi @sarathi125

It is getting only the second occurrence value, had changed to +1 but no use. Could you please check it @Palaniyappan

Can you let me know on which occurrence you need to extract the text.

If you have 3 times “want” then start from the third “want” and if you have 4 times “Check” then need to end with the 4th “check”?

@sarathi125,
Can we run this code in for each loop and get the text between two labels?

@sanju_RPA,

Yes, you can. Place the whole activities inside a for each then try.

May I know what going to be there in the for each?

@sarathi125
As you had earlier mentioned that , we gonna change the occurrence value +1 or +2. But i don’t know how many occurrences will occur. then how can i iterate this code in for each loop.

@sanju_RPA Do you know the word ?

@sarathi125sample.zip (313 Bytes)

Please check the attached file.
In this i need to extract the text between “PATH 1” and “Next” and these labels may repeat more than once.

See this: Test.xaml (9.3 KB)

Hi @bcorrea
image
Unable to view the Activity, may i know what is the package for this activity.

it is the uipath.core.activities, im on version 19.8.0

I’m on version 19.1.0
the activity is missing, may i know what is that activity.

Activity is Uipath.core.activities.Matches

Thanks to @Palaniyappan @sarathi125 @bcorrea
I think i got a solution by making a change in the code
“(?:PATH 1((?:.?\r?\n?))Next)”
It is working for my requirement.

2 Likes