Forum Discussion

setha's avatar
setha
New Contributor
13 years ago

VBScript and RegEx objects?

Hello,



I'm trying to use regular expressions from vbscript using TestComplete 8.6.  The following code snippet returns syntax error complainign about "As":



Dim r As New Regex( "Total[\s\S][\d.:]*", _RegexOptions.IgnoreCase)



When I try to do it this way:


Dim r

r = New Regex("Total[\s\S][\d.:]*", _RegexOptions.IgnoreCase)



I get a syntax error complaining about "New"



This syntax is from the MS vbscript language reference which is linked from the TestComplete help.



How does one create a new RegEx object using VBScript in TestComplete?



Thanks!

4 Replies

  • setha's avatar
    setha
    New Contributor
    Nevermind, I just figured out how to get this working:



    Dim regEx

    Set regEx = New RegExp

    regEx.Pattern = "Total[\s\S] [\d.:]*"

    regEx.IgnoreCase = True

    Set Matches = regEx.Execute(searchResults)

    For Each Match in Matches

    log.Message("Results: " + Match.Value)

    Next




    I am still curous as to why the As syntax is not recognized in TestComplete however.



    Thanks
  • AlexKaras's avatar
    AlexKaras
    Champion Level 3
    Hi Seth,



    > I am still curous as to why the As syntax is not recognized in TestComplete however.



    As any script language VBScript uses only variables of OleVariant type. That is why it does not need and does not support typed variables. The only thing that might be required is variable declaration (e.g. Dim myVar) at the beginning of the script in case 'Option Explicit' clause was specified as the first executable line of the script.
  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)
    Hi Seth,



    Dim VarName As Type is Visual Basic and VBA syntax, which is not supported in VBScript. Check out VBScript Language Reference in MSDN to learn more about VBScript syntax, what's supported and what's not.