REGEX help

Hi,

I’m running the MQTT binding in OH4 and I am trying to make use of the REGEX binding as well :slight_smile:
I have following stated under the “Incoming Value Transformations” in the MQTT generic item:

REGEX:(?<=1-0:31.7.0\(0)(.*)(?=\*A\)\\r\\n1-0:5)

But why is this not working when I am trying to transform an incoming MQTT string and capture 5.5 from the the paramter 1-0:31.7.0 in the string below?

/ELL5\\253941227_A\r\n\r\n0-0:1.0.0(230903100128W)\r\n1-0:1.8.0(00002557.779*kWh)\r\n1-0:2.8.0(00000000.162*kWh)\r\n1-0:3.8.0(00000730.106*kvarh)\r\n1-0:4.8.0(00000005.070*kvarh)\r\n1-0:1.7.0(0000.116*kW)\r\n1-0:2.7.0(0000.000*kW)\r\n1-0:3.7.0(0000.069*kvar)\r\n1-0:4.7.0(0000.050*kvar)\r\n1-0:21.7.0(0000.010*kW)\r\n1-0:41.7.0(0000.007*kW)\r\n1-0:61.7.0(0000.098*kW)\r\n1-0:22.7.0(0000.000*kW)\r\n1-0:42.7.0(0000.000*kW)\r\n1-0:62.7.0(0000.000*kW)\r\n1-0:23.7.0(0000.000*kvar)\r\n1-0:43.7.0(0000.000*kvar)\r\n1-0:63.7.0(0000.069*kvar)\r\n1-0:24.7.0(0000.014*kvar)\r\n1-0:44.7.0(0000.035*kvar)\r\n1-0:64.7.0(0000.000*kvar)\r\n1-0:32.7.0(241.2*V)\r\n1-0:52.7.0(241.0*V)\r\n1-0:72.7.0(241.1*V)\r\n1-0:31.7.0(005.5*A)\r\n1-0:51.7.0(000.1*A)\r\n1-0:71.7.0(000.5*A)\r\n!41FB\r\n

Side note, I am not sure if the “\n” and “\r” are being processed by the REGEX transformation. If I look at the item in the UI there are no “\n” or “\r”, but if I check the item via the REST API it is shown as above. But I have tried my REGEX statement with and without the extra characters and still get the same result.

Example:

Help appreciated.

\r\n means there’s a line break in the text, which is a bit tricky to handle in regex, since it sometimes only handles one line at a time. Not sure how the regex transformation in OH handles it though. But I would suggest to simplify the expression so you get some output working, and then add more to it if needed. Especially leave out the look-ahead/behind, they often complicate things more than they help.

Try something like this for example:
1-0:31\.7\.0\(0([0-9.]+)

1 Like

Simpler is better :slight_smile:
I’ve tried to google a solution to removing the first part of the output I get with your REGEX?

The output I get is:

1-0:31.7.0(005.5

and I need to remove:

1-0:31.7.0(0

I only want the 05.5 value.

swe Tack för hjälpen :slight_smile: /swe

.*1-0:31\.7\.0\(0([0-9.]+).*

1 Like

Thank you!