Home > DeveloperSection > Forums > QTP regular expression
jacob rasel
jacob rasel

Total Post:88

Posted on    June-20-2013 2:03 AM

 VB Script VB Script 

 1 Reply(s)
 1265  View(s)
Rate this:
Hi Expert,

I have problem with regular expression in QTP, can't understand why this pattern doesn't work:

Dim objRegExp
Set objRegExp = New RegExp
                objRegExp.Pattern = Replace(Replace(Replace("Millennium [AUT]", "\", "\\"), "(", "\("), ")", "\)")
                objRegExp.IgnoreCase = True
If objRegExp.Execute("Millennium [AUT]").Count < 1 Then
    Set objRegExp = Nothing
End If

Method Count return 0 value, could someone help, pls.

Sumit Kesarwani

Total Post:378

Posted on    June-20-2013 6:52 AM

Hi Jacob!

Your .Replace chain does not change the pattern "Millennium [AUT]" which searchs for "Millennium" follwed by " ", followd by one letter out of "A", "U", or "T". Your input "Millennium [AUT]" has a "[" where the pattern expects "A", "U", or "T".

So please follow the general rule when asking for solutuions of regexp problems: Give at least one sample input and its expected outcome.

Perhaps you meant:

set r = New RegExp
r.Pattern = "Millennium \[AUT\]"
set mts = r.Execute("Millennium [AUT]")
WScript.Echo mts.Count

I hope it helpful for you.

Don't want to miss updates? Please click the below button!

Follow MindStick