String Manipulation - after and before certain word and special character

Hi Guys,

I’m struggling to manipulate below string.
I’m trying to find a way to trim all the strings before the last “” and trim after the whitespace before the word “Exhibit”.
this is to apply this manipulation to rest of my documents.
Any suggestions or help would be much appreciated!

String: C:\Users\leek25\Desktop\UIpath\readwordTest****BEST test LIMITED Exhibit 100 .docx

Expected Manipulated String: BEST test LIMITED

I don’t think it’s a valid file name, because you can’t *** in the file name. Could you please provide a proper file name(mask the characters as needed) ?


Tyr This

Assign → StrValue = “C:\Users\leek25\Desktop\UIpath\readwordTest****BEST test LIMITED Exhibit 100 .docx”

Assign → StrValue = StrValue.Substring(StrValue.LastIndexOf("*")+1, 17)


1 Like


Length the string can vary at times
So it’s good to go for Regex which can handle even if the length is dynamic

If your string is in a variable named str_input
Use a assign activity like this

str_output = System.Text.RegularExpressions.Regex.Match(str_input,”(?<=\W\W\W\W).*(?=Exhibit)”).ToString.Trim

Cheers @KL1

1 Like

Sorry guys, was just trying to hide the name.

String: C:\Users\leek25\Desktop\UIpath\readword\BEST test LIMITED Exhibit 100 .docx

@KL1 - Exhibit 100 is constant always or is it dynamic? Could you please share few other file names ?

directory path and file names are dynamic and exhibit numbers increase per file. (ii have to check 50 - 100 files every fortnight)
this regex would be the option but i’m just trying to figure out how they work as i’m not quite familiar with it.

@KL1 - How about this??

path.GetFileNameWithoutExtension("C:\Users\leek25\Desktop\UIpath\readword\BEST test LIMITED Exhibit 100 .docx").split({"Exhibit"},StringSplitOptions.None)(0).trim

Below is the step by step construction of the code…

Please try and let us know, if this meets your requirement.

1 Like

Wow it works like a magic!! cheers for the help appreciate it! :):slight_smile:

1 Like

sorry file names are dynamic :frowning:

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