Announcement

Collapse
No announcement yet.

Regular expression in VBScript

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Regular expression in VBScript

    Hi all
    I have script which get http content and then search string. But when I want use regular in search string, it not work (regular: .*?). Also I using double quotes marks to express single quote mark.
    Any idea how rewrite script? Search string with regular works fine outside vscript
    Best regards.

    Code:
    server = "1.2.3.4"
    link = "/443/link"
    Set Http = CreateObject("WinHttp.WinHttpRequest.5.1")
    Http.SetClientCertificate "LOCAL_MACHINE\MY\cert"
    Http.Option(4) = 256 + 512 + 4096 + 8192 
    Http.Open "GET", "https://" & server & ":" & link, false
    Http.Send
    out = Http.ResponseText
    
    If InStr(1,out,"banner:apps:1:app:link::ILinkListener::"".*?class=""selected""") Then
    wscript.echo "ok"
    Else
    wscript.echo "error"
    End If
    
    Set Http = Nothing

  • #2
    Re: Regular expression in VBScript

    you can try,
    Code:
    Set Http = CreateObject("WinHttp.WinHttpRequest.5.1")
    
    server = "1.2.3.4"
    link = "/443/link"
    
    With Http
       .SetClientCertificate "LOCAL_MACHINE\MY\cert"
       .Option(4) = 256 + 512 + 4096 + 8192 
       .Open "GET", "https://" & server & ":" & link, false
       .Send
       out = .ResponseText
    End With
    
    Set Http = Nothing
    
    
    Set re = new regexp : re.Global = true : re.IgnoreCase = true
    
    wildcard = ".*?"
    re.Pattern = "banner:apps:1:app:link::ILiNKListener::""" & wildcard & "class=""selected"""
    
    If re.Test(out) then
       wscript.echo "ok"
    Else
       wscript.echo "error"
    End If
    /Rems

    This posting is provided "AS IS" with no warranties, and confers no rights.

    __________________

    ** Remember to give credit where credit's due **
    and leave Reputation Points for meaningful posts

    Comment


    • #3
      Re: Regular expression in VBScript

      Hi Rems, thank you very much for help! It works now.

      Comment

      Working...
      X