Reputation: 97
I keep getting the error: Syntax error in regular expression. I've made my regex pattern simpler and simpler to try and work around my guesses on what is causing the problem. I'm stuck now.
Here's the pattern: (?<=\d\s\x22)(.*?)(?=\x22)
Here's the haystack:
Dhcp Server \\192.168.7.111 add scope 10.10.1.0 255.255.255.0 "UPS-VLAN 1005" "Monitor APC UPS in data closets"`
Dhcp Server \\192.168.7.111 Scope 10.10.1.0 Add reservedip 10.10.1.22 00a0a0aa0000 "SITE-SEA-100-1A00-APC" "APC Room 1C00" "DHCP"
Dhcp Server \\192.168.7.111 Scope 10.10.1.0 Add reservedip 10.10.1.123 00a0a0aa0000 "SITE-SEA-100-13B48-APC" "" ""
Dhcp Server \\192.168.7.111 Scope 10.10.1.0 Add reservedip 10.10.1.122 00a0a0aa0000 "SITE-SEA-100-12B27-APC" "" ""
Dhcp Server \\192.168.7.111 Scope 10.10.1.0 Add reservedip 10.10.1.103 00a0a0aa0000 "SITE-SEA-100-2C24-APC" "" ""
Here's the intended match: UPS-VLAN 1005
Here's the code in question:
strLine = unparsed_scopename_file.ReadLine
Set objRE = New RegExp
With objRE
.Pattern = "(?<=\d\s\x22)(.*?)(?=\x22)"
.Global = False
End With
Set objMatch = objRE.Execute(strLine)
I get the error on the last line.
FWIW, this was my more recent pattern, but I am given to understand that quantifiers cannot be used in look behinds: (?<=\.\d+\s\x22).*?(?=\x22)
Edit: So the problem is the lookbehind, which is not supported by VB. Can anyone suggest a pattern that will match the intended target and only the intended target?
Upvotes: 2
Views: 379
Reputation: 336478
VBScript is based on ECMAScript, and ECMAScript's regex implementation doesn't support lookbehind assertions at all.
Therefore (?<=\d\s\x22)
can't be used. Use
"(?:\d\s\x22)(.*?)(?=\x22)"
and check the contents of group 1 for the relevant part of the match.
Upvotes: 2