Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
replace with regular expression
#1
Solved: 11 Years, 3 Months, 3 Weeks ago
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
Reply
#2
Solved: 11 Years, 3 Months, 3 Weeks ago
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.
Want to fast track your QTP/UFT Learning? Join our UFT Training Course
Reply
#3
Solved: 11 Years, 3 Months, 3 Weeks ago
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.
Reply
#4
Solved: 11 Years, 3 Months, 3 Weeks ago
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
Reply
#5
Solved: 11 Years, 3 Months, 3 Weeks ago
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Need Any digit in xpath path using Regular expression Priyam 1 3,484 10-05-2016, 11:05 AM
Last Post: Ankur
  Regular expression to read two words in lowercase, uppercase and with and without spa sarahq49 1 3,351 04-09-2015, 01:56 AM
Last Post: sarahq49
  Regular expression and script optimisation Padmavathy 1 3,817 03-30-2015, 11:46 AM
Last Post: supputuri
  Regular expression in descriptive programming testernc 1 16,564 12-08-2014, 06:38 PM
Last Post: anshika.agarwal
  need a regular expression. anu05446 0 3,114 11-26-2014, 03:00 PM
Last Post: anu05446

Forum Jump:


Users browsing this thread: 4 Guest(s)