Micro Focus QTP (UFT) Forums
replace with regular expression - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Regular Expressions (https://www.learnqtp.com/forums/Forum-UFT-QTP-Regular-Expressions)
+--- Thread: replace with regular expression (/Thread-replace-with-regular-expression)



replace with regular expression - kamalteja - 04-11-2008

Hi,
I want to know
How to use regular expression in replace function
I want to discard numbers in text
Below is the issue
Text1 = "hello1234"
replace(Text1,[0-9],"") 'This line throws syntax error


RE: replace with regular expression - Ankur - 04-11-2008

regular expressions cant be used in comparison statements...

you can use RegEx object to accomplish this task...Refer QTP help to get more info about this object.


RE: replace with regular expression - aditya - 07-15-2008

Hi,
"02 Jul 2008 18:38 -sasdgadfgasdfgagdgaghd"
I need to replace "02 Jul 2008 18:38 "with regular exp. how i can do that plz help me i tried lot of ways but not getting.
We are using descriptive programming.


RE: replace with regular expression - surya_7mar - 07-28-2008

The below example i am tryiong to convert all the <TODAY> with Current Date.

In the same way you can pass any regular expression.

Code:
str  = "Today is <TODAY>"

Dim oRe, oMatches,Match,str2
Set oRe = New RegExp
oRe.IgnoreCase = True
oRe.Global = true
oRe.Pattern = "<TODAY>"
Set oMatches = oRe.Execute(str)
For each Match in oMatches
    str = Replace(str, Match.Value,Date)          
Next

print str 'will print Today is 07/28/2008


RE: replace with regular expression - Rajashekar Gouda - 07-28-2008

My answer is also same and resembels like Anku and Surya's comments but still to make easiar to understand i m ginving the expample here. Hope it may helpful for Kamal

Code:
'Function ReplaceTest(patrn, replStr)
  Dim regEx, str1               ' Create variables.
  str1 = "hello1234"
  Set regEx = New RegExp            ' Create regular expression.
  patrn="hello1234"
  replStr="hello"
  regEx.Pattern = patrn            ' Set pattern.
  regEx.IgnoreCase = True            ' Make case insensitive.
  ReplaceTest = regEx.Replace(str1, replStr)   ' Make replacement.
'End Function

MsgBox ReplaceTest     ' Replace 'fox' with 'cat'.

Regards
Raj