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

That’s the thing: it SHOULD be simple but it never is

1 Like

don’ t get me started… :slight_smile:

Try looking at this post, it may help a little https://community.openhab.org/t/why-doesnt-my-regex-work-the-way-it-does-on-the-test-sites/52436/12?u=ianj001

No one figures out regular expressions. They are arcane magic that we only use but no mortal can truly understand them.

OK, so here is how to debug. Gradually build up to the regex until it stops working. Then at least you will know where it is going wrong.

So something like:

  • (.*)
  • .Camera(.)<.*
  • .Camera.–.(.)<. //return match everything between the one character after the – and the <

and so on. Be as broad as you can be. The more specifically you define the REGEX the more likeliy that there will be a small change in the output or that you will have an error that breaks the match you want.

This may not be best practice but I find it is the best way to get to something that works without being a regex expert.

Ian, Thanks, yes I had seen that post and it is more or less what I did, the screenshot of the ‘in vitro’ working REGEX is actually from regex101.com. Worked perfect there. I put it in Openhab, factored the double escapes and presto…nothing. :slight_smile:
Anyway, its a challenge, I’ll keep trying.

@rlkoshak
Thank you, yes, I was truly getting ahead of the facts while in reality I wasnt even worthy to polish the shoes of the wizard’s apprentice.
Nevertheless, your suggestion is a good one, I’ ll give that a try. After all, I got the Number item to work, should be able to get the string item to work as well.

Oh well, keeps me off the street and out of trouble

Interestingly though even (.*) does not work.Hmmmmmm, perhaps the problem lies somewhere else entirely

EDIT: I think I have it solved. I’ ll check a bit more and report back later

@vzorglub
@ianj001
@rlkoshak
OK, got some results. This is what happened. When after Rich suggestion to start with a simple REGEX and I didnt even get(.*) to work, I started to think the problem must be in the item definition.
I checked and compared to the working Number RegEx expression and I simply couldnt see anything wrong with it… but there must be something wrong.
So, I copy the working Number RegEx line, give it another itemname of course and yes, as expected, I have 2 working outputs, albeit both the same number and no string
Then in my copy string, I change the itemtype from “Number” to “String”, change [%d] to [%s] and yes, still output. identical output, but one as number and the other now a string.
I change the regex to(.*), yes, the entire HTML page now in my string.
I gradually build it up and working.

Ergo… the problem was NOT in the regex, but somewhere in the itemdef. Don’ t ask me what, I checked and checked and compared, but couldnt find it.

Oh well, works now… but yes, it is still magic and I guess somewhere a REGEX deity took pity on me.

Thank you all for your help that eventually made me pin down where the problem was not and therefore where it should be. I may give REGEX another chance

1 Like

You were missing the opening [.

{ http="<[motionCam...

Once you know where to look, sometimes a fresh pair of eyes can immediately find the answer.

I would have expected to see something in openhab.log about not being able to parse the http config though.

1 Like

Oh darn, hit me over the head with a baseball bat, how could I have been so blind.
But yes you are right, we tend to be blind for our mistakes, both in real life as well as in coding.

The stupid thing is that I already had my suspicion on the part before the regex, I checked and checked… and still didnt see it

I did check the openhab log… no such error and also my editor didn’t flag an error on that

And I do state that probably 80% of the issues I had with openhab was coz of typo’s
Thanks!!!

Glad you got it worked out. I had an issue with one of mine, at the end of the mqtt after state I had :: and that was causing the REGEX to be ignored. Typo’s can drive you crazy, fresh eyes can sometimes fix it.

1 Like

Definitely. My only defense is that sometimes I immediately spotted errors in other peoples code who posted their problems on the Forum. Maybe that balances it out a bit… but still, I go sit in a corner now and feel ashamed :slight_smile:

Now I just cannot not see that error

1 Like