[SOLVED] Can't figure out why one RegEx isn't working

I defined 2 RegEx expressions and one is not working:

I have a webpage that I like to extract two pieces of data of.
One of the (RegEx) extractions works, the other renders nothing and I cant figure out why.
I setup my http service with the proper ip like so:


That page renders the following text:

<– back

<b>Camera 0 -- Beneden</b> Connection OK


I want to extract the number ‘0’ as well as the word ‘Beneden’

I do that as follows:

Number VT_Camera_number "Camera number [%d]" <camera> (Security)  { http="<[motionCam:600:REGEX(.*Camera\\s(\\d).*)]" }
String VT_Camera_name "Camera name [%s]" <camera> (Security) { http="<motionCam:600:RegEx(.*Camera\\s\\d\\s--\\s(.*)<\\/b>\\sC.*)]" }

oddly though I have NO problem extracting the number, but I cannot extract the name, the string remains empty and I cant figure out why.
What the defined REGEX does is it looks for the word “Camera” followed by a space, followed by a digit, followed by a space, followed by two hypens, followed by a space, followed by any piece of text (That should be the word"Beneden"), followed by the html code for end-bold, followed by a space and a capital C
I tested the RegEx, and that should be OK (see fig), but ofcourse for OpenHab I had to escape the escape characters, hence the ‘\\’

Any ideas about what I am doing wrong are appreciated

This, dear readers was where the fault was, not in the REGEX itself. nevertheless, this thread contains some useful info on how to track mistakes in REGEX

In the second one did you mean to use RegEx instead of REGEX?
Also have you tried using the substitute something like

String VT_Camera_name "Camera name [%s]" <camera> (Security) { http="<motionCam:600:REGEX(s/.*Camera\\s\\d\\s--\\s(.*)<\\/b>\\sC.*/$1/g)]" }

Thank you, that was extremely stupid of me. Didn’t notice that though I checked and rechecked the string.
But sadly neither that one, nor your second suggestion made a difference so I am still stuck. And here I thought I had finally figured out Regular Expressions :frowning:

I have never got these myself… I gave up a long time ago. They make my brain go boom :exploding_head::bomb:

1 Like

Can you post the html response so we can have go, please?

not sure where I can find the HTML response

You posted it above but in image format


Motion 4.0 <– back

Camera 0 -- Beneden Connection OK

hmm if I put it between brackets, it renders/parss the html code but without brackets it looks like this:
<!DOCTYPE html> <html> <head><title>Motion 4.0</title></head> <body> <a href=/0/detection>&lt;&ndash; back</a><br><br> <b>Camera 0 – Beneden</b> Connection OK<br> </body> </html>


Thank you Vincent, but that sadly didnt do anything either. Ofcourse in openhab I had to escape all the escape codes, so it became:
REGEX(.*Camera\\s\\d\\s\\W\\s([a-zA-Z]*))]" }
but the item remains empty

You are missing a "

REGEX(".*Camera\\s\\d\\s\\W\\s([a-zA-Z]*))]" }

No, that only seems so. The entire channel looks like this:

{http="<motionCam:600:REGEX(.*Camera\\s\\d\\s\\W\\s([a-zA-Z]*))]" }


Did you try without escaping the \ ?

yes, that’s how I started and I immediately had that signalled as multiple errors and my itemsfile was ignored… then after reading up on the documentation for Openhab/REGEX, I understood the escape code needs to be escaped…
Somehow, I can’ t shake the idea that maybe that is where the problem lies. did I forget to escape something? did I escape something too much?
Regardless, with any isolated"\" my code editor starts protesting and the item doesn’t work

OK, try that:


nope, immediately flagged as error coz of the unescaped escape code in front of [ and ]
Ignoring that error and saving anyway results in the entire itemsfile simply being ignored.
Escaping those escapes again makes the items file used again… but without result

Don’t know :exploding_head:

Well, you gave it your best so I am grateful regardless :slight_smile:

Its odd as the REGEX in my Number item just works

It’s the last time a get near regex
Every time I use javascript transform or pass it though node-red instead

I fully understand that :slight_smile:Maybe I should brush up on my javascript. Just hoped REGEX would be simpler in what should be a simple transformation