Extract specific string from multiple - Using Regular Expression

Hi All,

I want to extract the last row as where Delivery - Open is mentioned which is immediate row to Additional Information Requested using Reg Ex.

Delivery - Additional Information Requested - 2022-08-29 15:46:51 - a.als.a
Delivery - Open - 2022-09-05 09:45:54 - ll.als.a
Delivery - Work in Progress - 2022-09-06 10:11:17 - ooak
Delivery - Reviewed - 2022-09-12 08:13:51 - kkkais
Delivery - Additional Information Requested - 2022-09-18 12:15:06 - kan.skd
Delivery - Open - 2022-09-28 10:22:59 - kaj.sji
Delivery - Work in Progress - 2022-09-28 11:58:45 - abc.jsh

Expected output
Delivery - Open - 2022-09-28 10:22:59 - kaj.sji

@Yoichi seeking help

Thanks,
Rushi

@Athawale_Rushikesh

Please try this

System.Text.RegularExpressions.Regex.Matches(str,"(?<=Additional Information Requested.*\n).*")(System.Text.RegularExpressions.Regex.Matches(str,"(?<=Additional Information Requested.*\n).*").Count -1).Value

image

cheers

HI @Athawale_Rushikesh

Check out this expression

System.Text.RegularExpressions.Regex.Matches(yourString,"\S.*\n(?=Delivery - Work in Progress)")(System.Text.RegularExpressions.Regex.Matches(yourString,"\S.*\n(?=Delivery - Work in Progress)").Count-1)

image

Regards
Gokul

Hello @Athawale_Rushikesh

You can use the matches activity to get the relevant data to a List and then use the index to get the required line of data as beloe.

Then use below expression to get the value: strVar is the output of matches activity.
strVar(strVar.Count-1)

image

Hi @Athawale_Rushikesh
Try this pattern - Delivery - Open.*$


in Regex Builder action in UiPath

Thanks!!!

Hi @Anil_G ,

Solution is working as expected but it throws error if no “Additional Information Requested” tag is present in string. It should return empty without any error.

Regards,
Rushi

Hi @Athawale_Rushikesh

Try to use this expression in If activity

System.Text.RegularExpressions.Regex.IsMatch(yourstring,"(?<=Additional Information Requested.*\n).*")

Regards
Gokul

Hi @Rahul_Unnikrishnan & @Kaviyarasu_N

Thanks for your response, however we want to extract the Open tag details which comes only after Additional Information requested. If we do not see any tag as Additional Information requested it should not return Open Tag details also

Regards
Rushi

@Athawale_Rushikesh

First check if the additional information is present in the string using contains… if you want to check the count then use str.split({“additional info…”},StringSplitOptions.None).count > 2 then it means you have two of them then use the match…that should solve the issue

Use >1 if you want to extract even if it is present only once

Cheers

@Athawale_Rushikesh

You can Split the entire string using “Additional Information requested” as below.

first get the input string to variable “strInput”. Then use the below expression to split the string with “Additional Information requested”
strInput.Split(“Additional Information requested”)

The to get the last content use the below expression and get result to a string variable
strList(strList.Count-1)

Then Pass the above output variable to the Matches activity as explained earlier.

image

Thanks

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