Regular expression in VBScript

Home Forums Scripting Windows Script Host Regular expression in VBScript

This topic contains 2 replies, has 3 voices, and was last updated by Avatar jeff.schumacher 7 years, 2 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • Avatar
    h0ndzik
    Member
    #159149

    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.

    server = “1.2.3.4”
    link = “/443/link”
    Set Http = CreateObject(“WinHttp.WinHttpRequest.5.1”)
    Http.SetClientCertificate “LOCAL_MACHINEMYcert”
    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
    [/CODE][CODE]
    server = “1.2.3.4”
    link = “/443/link”
    Set Http = CreateObject(“WinHttp.WinHttpRequest.5.1”)
    Http.SetClientCertificate “LOCAL_MACHINEMYcert”
    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
    [/CODE]

    Rems
    Rems
    Moderator
    #228204

    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_MACHINEMYcert”
    .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 = “[COLOR=”Red”].*?[/COLOR]”
    re.Pattern = “banner:apps:1:app:link::ILiNKListener::””” & wildcard & “class=””selected”””

    [B][SIZE=”3″]If re.Test(out) then[/SIZE][/B]
    wscript.echo “ok”
    Else
    wscript.echo “error”
    End If

    /Rems

    #375378

    Re: Regular expression in VBScript

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

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.