How to extract string after specific string

I have a text file with so many lines. From the entire text file I need to extract all the repeated strings in the file after specific string. Let’s say Input is a text file with so much content

Animal.Name=“Forest Elephant_1” <Has it’s own power.>

Output should be:
Tiger
Forest Elephant
African Bush Elephant

Need help in doing this. Thanks in advance.

Hi ,

Please attach some sample input txt file.

Happy Automation :slight_smile:

Thanks ,
Priyanka.

sampleText.txt (862 Bytes)

Attaching image too.Again it is a sample file with few lines.

Hi @Kavya_Mamidishetti2

Check with this regex

Regards
Gokul

1 Like

@Gokul001 Thanks.Will look into it.

@Kavya_Mamidishetti2

It is working for you
If not, let me know

Regards
Gokul

pls check
Split String.zip (41.6 KB)

@Gokul001 It is throwing an error saying “End of Expression Expected”. I passed the expression into pattern property “Matches activity”. Provided input variable and output variable. I am very new to regular expressions concept. Correct me if I did wrong.

Regards
Kavya

@Mr.H Thank you will check it.

Hi @Kavya_Mamidishetti2

  • Use Assign Activity

Create Variable Rg1 = System.Text.RegularExpression.Regex.Matches(“Input_Variable”, “(?<=Animal.Name=”)(\S.+)(?=_)").Tostring

Can you please share the screenshot of workflow?

Regards
Gokul

@Gokul001

There is small mistakes in your method of writing that code, actually Matches returns collection not a single value, so code to be used is

data = System.Text.RegularExpressions.Regex.Matches(input_string,“(?<=Animal.Name=.).*(?=_\d+)”).Cast(Of Match).Select(Function(m) m.Value.ToString).ToArray()

@Kavya_Mamidishetti2 check this

here data is collection of values from regex pattern [DataType : String], input_string is the input text from which u need to extract the data

Hope this helps you

Regards,
Nived N

1 Like

here it is Rg1 is of string type.

@Kavya_Mamidishetti2 - Is this your expected result?

  1. Read Text file and save the output has StrInput

  2. Matches activity…

Regex pattern …Since there is already a double quote in the string…i have escaped with another so it wont error…

 "(?<=Animal.Name="").+(?=_)"

If want to store the results in an Array…then use the below code…

ArrItems = IEnRegEx.Select(function(x) x.ToString).toarray

Hope this helps…

@NIVED_NAMBIAR Hey it worked. Thanks a lot but I didn’t understand the functionality behind the code. The code seems to be a bit advanced to me. Can you suggest any links to understand how functions work?

Regards
Kavya

@Mr.H Yeah. It worked. Thank you so much for the file.

Regards,
Kavya

@prasath17 Yes prasanth. That’s the expected result. It is working. Thanks a lot.

Regards
Kavya

1 Like

Hi @Kavya_Mamidishetti2

You can imagine that code functionality to the Matches activity in uipath,

check here

Regards,
Nived N

1 Like

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