My goal is to extract the value, which is 1 in this case. I tried many things in the .items file but without success:
Tried to get it as a substring:
String DO1Name “[REGEX(=(.*?);):%s]” { channel=“http:url:daenetip3:doName1” }
Result is: [NULL]
The interesting thing is as per the docs, this should work.
Tried to replace strings and leave only the “1” but with partial success:
String DO1Name “[REGEX(s/AS0=/ /g):%s]” { channel=“http:url:daenetip3:doName1” }
Result is: [ 1;]
I didn’t find a way to replace with “” (delete it) but only with at least one char
Also I didn’t find a way to replace at the same time the “;” string so i can have only the “1” result.
It is really difficult to see what’s going on here. Please use code fences for all code and logs posted to the forum.
```
code goes here
```
So you are trying to transform the state of the DO1Name Item using the REGEX transformation. Usually when extracting values like that the REGEX goes in the Thing configuration so you can use a Number Item.
An Item’s label usually has two parts: "<label> [<state>]". <label> is the static text that appears before the state as part of the label. The state shows the current state of the Item.
Often you’ll just see a String formatting field for the state (e.g. %d for integers, %.1f for a floating point value rounded to the nearest tenth, %s for a String).
Occasionally you will want to show the user the state transformed in some way. So far so good.
However, in OH one thing is a little different from regular use of REGEX. If you are using a capture group, only the first capture group is returned and the REGEX must match the entire String. The first capture group is what gets returned by the transformation.
So if you want the “1” from “AS0=1;” the expression needs to be something like .*AS0=(.*);.*. I’m assuming that the full value of the String has multiple lines or other entries and we need to match those too both the text before “AS0=” and the text after “;”.