Regex question

Forum to ask for any help
Post Reply
ChrisB75
Posts: 52
Joined: Sun Feb 17, 2013 1:11 pm

Regex question

Post by ChrisB75 » Sat Nov 23, 2013 7:00 pm

I'm struggling with Regex :?
The following regex works in Demopad but not in http://www.regextester.com/ or other testers I found, in fact, there even seems to be disparity between different testers :?

<state id=".*" service="urn:upnp-org:serviceId:Dimming1" variable="LoadLevelStatus" value="(.*)"></state> with </state> as the terminator

I don't know much about regex so the answer might be obvious to someone. Does anyone know why this is? Also, I want to find 2 terms in one xml file but can't work out how to do this - despite a great guide at http://www.silverstones.com/thebat/Regex.html; specifically, I want to send the value of LoadLevelStatus to a number providing Device_Num_9 is also present;

<root LoadTime="1385139141" DataVersion="139142321" UserData_DataVersion="139141022" TimeStamp="1385229600" ZWaveStatus="1" LocalTime="2013-11-23 18:00:00 N">
<Device_Num_9 status="-1">
<states>
<state id="135" service="urn:upnp-org:serviceId:SwitchPower1" variable="Status" value="1"/>
<state id="136" service="urn:upnp-org:serviceId:Dimming1" variable="LoadLevelStatus" value="10"/>
<state id="137" service="urn:micasaverde-com:serviceId:HaDevice1" variable="Configured" value="0"/>
<state id="138" service="upnp-rfxcom-com:serviceId:rfxtrx1" variable="Assocation" value=""/>
<state id="139" service="upnp-rfxcom-com:serviceId:rfxtrx1" variable="KopplaProgrammed" value="1"/>
</states>
<Jobs/>
<tooltip display="0"/>
</Device_Num_9>
</root>

Any help would be much appreciated :)

ChrisB75
Posts: 52
Joined: Sun Feb 17, 2013 1:11 pm

Re: Regex question

Post by ChrisB75 » Mon Nov 25, 2013 12:01 am

I've been trying to get this to work but it ain't happening :?
Pulling the file as json rather than xml, the following works in the regex tester at
(?:Device_Num_9)|(?:"LoadLevelStatus", "value": ")([0-9a-zA-Z-:]*) and returns the value - I appreciate I don't need the a-z or A-Z or - or : which can be removed, although I'm not sure what to use to get a 1 or 2 digit value - /d/d maybe? Anyway, the problem is that it doesn't work in Demopad!?
Help pleeeaase :?

ChrisB75
Posts: 52
Joined: Sun Feb 17, 2013 1:11 pm

Re: Regex question

Post by ChrisB75 » Mon Nov 25, 2013 12:04 am

Whoops, forgot to put which regex tester I used, d'oh - http://regexlib.com/RETester.aspx

trevorst
Posts: 160
Joined: Wed Jul 18, 2012 3:45 pm
Location: Tacoma, WA

Re: Regex question

Post by trevorst » Mon Nov 25, 2013 3:35 am

Try this... The single period gives one digit, two periods should give two.
([0-9a].)

ChrisB75
Posts: 52
Joined: Sun Feb 17, 2013 1:11 pm

Re: Regex question

Post by ChrisB75 » Wed Nov 27, 2013 11:34 am

Sussed it! :D With the usual help from Demopad of course :D I'm posting this under Lightwaverf and Veralite on the General Forum.

Post Reply