QTP regular expression

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.
Last updated:6/20/2013 6:52:49 AM

1 Answers

Sumit Kesarwani
Sumit Kesarwani

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.

Answer