user2535887
user2535887

Reputation: 13

vbscript regex to handle word before OR after another word using a negative look ahead

I have the pattern below in a vbscript to turn my lights on/off. It captures the case "turn on the third bedroom light." However, is there an elegant way to also capture the case "turn on the light in the third bedroom" using an all-in-one pattern?

I know I can separate out the (light|lite) case in a separate pattern and use conditional logic, but I was looking for an all in one elegant pattern as I'm still learning regex.

Keep in mind that whatever pattern must also exclude the case "third bedroom closet" as shown in the pattern below. Also note that vbscript doesn't support negative look behind (I think).

oRegExp.Pattern = "(third).(bedroom (?!closet)).*(light|lite)"
if oRegExp.Test(sVoice) then gProcessLight home.ThirdBedroom.Light,vPropValue

Upvotes: 1

Views: 136

Answers (1)

Ansgar Wiechers
Ansgar Wiechers

Reputation: 200203

You'll have to use alternatives for this:

(third bedroom (light|lite)|(light|lite).*third bedroom (?!closet))

Upvotes: 0

Related Questions