Question

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
Was it helpful?

Solution

You'll have to use alternatives for this:

(third bedroom (light|lite)|(light|lite).*third bedroom (?!closet))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top