Extract dynamic text from string

Hello,

I have to read texts from word doc and extract few texts which are dynamic by nature. I am able to achieve desired result by using substring and their positioning method but due to dynamic by nature the same method is not working in each case(if value change). I am attaching sample string output in which i need to extract text “SAP GRC Process Control” which is dynamic and below is the code from which i am able to get desired result.

Approver.Substring(Approver.IndexOf(“IT Service(IT/Non-IT)”)+24,23)

If possible please suggest any other alternatives to extract text between “IT Service(IT/Non-IT):” and “…9” from attached image.

substring

we can try Regex:
grafik

And when we do make it more general we anchor on : and stop on digit followed by stop
grafik

For a first introduction to regex have a look here:

Just to confirm

That dots(…) in the quoted text and in the image will be the redundant value. And it seems like a OCR extraction that gives that non-alphabet characters.

Am I right on that?

If yes, once you get the text after using above regex mentioned by Peter, you may have to use regex to filter only alphabets.

@ppr I tried with regex but not getting relevant result

Please find the following attachment of input string with variable name “Approver”, output that i am getting and regex that i am using and suggest where i am wrong.

Regex that i am using:

Input String from which i am extracting value:

Output that i am getting:
Output_Image

Cheers!!!

WE cannot Use a toString on the Output of a Matches Activity Output.

Gibt a try on
YourMatchesOutputVar(0).toString

Or use the the reges.match Methode directly

@ppr
Could you please suggest how to use regex directly in Assign activity

System.text.regularexpressions.Regex.match(Yourstring,yourpattern).value

@ppr Yes i tried it in same way but getting blank result

In below code Approver is input string with datatype string and i am assigning the output in variable xyz with datatype string.

System.Text.RegularExpressions.Regex.Match(Approver,“(?<=IT Service(IT/Non-IT):).*(?=9)”).value.ToString

System.Text.RegularExpressions.Regex.Match(Approver,“(?<=IT Service(IT/Non-IT):).*(?=9)”).value

System.Text.RegularExpressions.Regex.Match(Approver,“(?<=IT Service(IT/Non-IT):).*(?=9)”).ToString

Kindly note that we had excaped the brackets etc. \( .... \)
ensure you have done the same

Cross checked during a debug paused by breakpoint within UiPath immediate panel:
grafik

Yes i have escaped the brackets etc. \( .... \) and still getting blank output while debugging.

I am using pattern:
System.Text.RegularExpressions.Regex.Match(service,“(?<=IT Service(IT/Non-IT): )(.*?)(?=9.)”).Value

But you have noticed that on immediate panel it was passing the test?

just check on yourInputString for the regex that the pattern can be matched e.g. is maybe a space between ) and :

@ppr It is working fine now, there was issue with extra spaces. Thanx for you help.

Now output string looks like attached image and have to remove extra dots. I tried with below options but it didn’t work as expected.

First method:-
System.Text.RegularExpressions.Regex.Match(servicenew, “([1]*$)” ).value

Seconf Method:-
servicenew.TrimEnd

Output string from which have to remove dots:

test


  1. A-Za-z ↩︎

Hi @ppr,

Its working fine by using substring with Length method.

Thanx for you time.

Cheers!!!

@shekharhimanshu627
feel free to do some testing and when it is done please close the topic by marking the solving post as solution.

In the case of you want trim/remove the ending dots you can do following:

  • send us the string with containing the dots
  • check with ASC(yourMatchResultString.Last()) for more details - it will retrun the ascii code of the dot char

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