Regex Replace Challenge

studio
regex

#1

I have a string like below
This is a test and the Test is part of unit testing

I want to replace all the “test” with “xxxtestxxxx” so the output should be
This is a xxxtestxxxx and the xxxTestxxxx is part of unit testing -> (including the original cases(test/Test)

I’m using the following function
System.Text.RegularExpressions.Regex.Replace(“string”,“regexpattern”,“replacestring”)
System.Text.RegularExpressions.Regex.Replace(tempString,"(?i)\btest\b", “xxxtestxxxx”)

My challenge is how do I access the matched expressesion ouput (2nd parameter) in the last parameter replacestring…

I hope I made myself clear…


#2

any help ?


#3

Why not use String.Replace

For eg

Str.ToLower.Replace(“test”,“xxxtestxxxx”)


#4

Hi,

System.Text.RegularExpressions.Regex.Replace(tempString,"((\btest\b)+", “xxxtestxxxx”)

Regards,
Arivu


#5

thanks for the replies… the above suggestions may not work for me…
what I want is the input string could be case sensitive… so for ex : “test” or “Test” or “teST” etc., and the replacement should happen

xxxtestxxx
xxxTestxxx
xxxteSTxxx

with the above suggestions I will not be able to get that… hope I clarified…


#6

stringReplace.xaml (7.5 KB)


#7

can you help me with pattern for page numbers of a pdf like 1/1 or 1/2 or 1/10 which needs to be replaced with empty string


#8

Hi - here is the example

pattern - (\d*/\d*)

in UIPath assign activity you an probably achieve like below [did not test… but it should work]

System.Text.RegularExpressions.Regex.Replace(yourstring,"(\d*/\d*)/g", “”,"")


#9

Its working bro, thank you so much for help.