Jean
Jean

Reputation: 13

Correct syntax for VBScritp for using regex.replace with RegexOptions.Singleline

I have been unable to get correct syntax for VBScript in using regex replace with RegexOptions.Singleline

Goal is to extract some text from strSearchString and using back references to hold extracted data I want with $1=abc-123 and $2=122 $3=133 $4=144 $5=155

I can get the regex pattern to work on various RegEx online testers using the singleline option, but unsure on correct syntax for VBScript and I get a pop-up error on various things I have tried.

Error:  Object required: ' RegexOptions'
Code: 800A01A8

Here is my code:

Set objRegEx = New RegExp

objRegEx.Global = True
objRegEx.Pattern ="(\S+)\r\n.+\040ip\040address\040(\d+)\056(\d+)\056(\d+)\056(\d+)"

strSearchString = "abc-123" + vbCrlf + " Company Name Street Address" + vbCrlf + " ip address 122.133.144.155"

Wscript.Echo strSearchString

strExtract = objRegEx.Replace(strSearchString, objRegEx.Pattern, "test $1 $2 $3 $4 $5", RegexOptions.Singleline)

Wscript.Echo strExtract

Upvotes: 1

Views: 115

Answers (1)

walid toumi
walid toumi

Reputation: 2272

Vbscript not support singleline mode but you can try this pattern:

(\S+)[\s\S]*ip\saddress\s(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})

Upvotes: 1

Related Questions