OH3 regex state transformation for string channel of http thing does not seem to work

  • Platform information:
    • Hardware: arm/4GBRAM/32GBSDcard
    • OS: Linux Openhabian 5.4.83-v7l+ #1379 SMP Mon Dec 14 13:11:54 GMT 2020 armv7l
    • Java Runtime Environment: openjdk version “11.0.9” 2020-10-20 LTS
      OpenJDK Runtime Environment Zulu11.43+88-CA (build 11.0.9+11-LTS)
      OpenJDK Client VM Zulu11.43+88-CA (build 11.0.9+11-LTS, mixed mode)

I’m attempting a regex state transformation for a string item linked to a channel of an http item.
While the original value is returned properly, I run into issues the moment I’m attempting a REGEX transformation.
YES - I have installed the REGEX transform service :wink:

  1. full URL for value is: http://172.16.60.40/command.html?P=sosecret&AS9=?&
    … URL returns “AS9=1;” when using web browser.
  2. Base URL of thing is: http://172.16.60.40/command.html?P=sosecret&
  3. State URL extension is: AS9=?&
  4. OH returns value “AS9=1;” for string item as expected - so far so good.
  5. I’m attempting to use regex to extract the 1 after AS9=
  6. regex expression of (?<=AS0=)\d should suffice
  7. setting the State transformation value of the channel to REGEX:(?<=AS0=)\d does not work.
  8. using REGEX:.* does not work either.

What am I missing here?

Any errors or warnings in the logs?

You need to put the parenthesis around the part that shall be returned.
For whatever reason your expample value returned from browser resp. http binding ( which is described as AS9=1 ) does not match with what you use in the expression ( AS0 ).
Either a typo here in the description or a typo in your regex.
So shouldn’t the REGEX be:

REGEX:AS9=(\d)

I need to say that I 've never used regex in OH but in other linux stuff.

no only info entries

Well spotted wrt the 9 vs 0. That was a copy pased issue when starting this topic.
When using REGEX:AS9=(\d) as state transform value the output seems to be frozen. there is not even a change of the value appearing in the event log.
Should REGEX:(.*) not returning the original value? the moment I use it and change the state of the device there is no change reported in the events logs anymore…
As if the regex transform service is not working completely.

Correct. Do you use the parenthesis in your code because also for that part they are missing in your previous post.

So REGEX:(.*) is now working after I reinstalled the regex transform service.
REGEX:AS9=(\d) or just REGEX:(AS9=) don’t. The Itm value just seems to freeze at its last state and does not get updated anymore if the state changes. As if the pattern is not getting processed by the transformation service.
I do not see any errors with regard to REGEX module in openhab.log

Ok I finally got it now: The regex pattern has to match the full string including all parts you dont want. the part you want has to be in parenthesis:

The original string in my case is:

somestringstostartwithAS9=1;somestringstofollow…

I’m interested in the one digit value after the =.

so the pattern would be
.*AS9=
for everything in front of my value in question.

*(\d)*
for the actual value

followed by
.*
to match the rest of the string.

putting it all together:
REGEX:.*AS9=(\d).*

Thanks!

3 Likes