Won’t help… Thanks for the hint. From Forum posts I got that the REGEX in Openhab seems to work a little different. But could not solve my problem with that.
Went to JS and a split funktion for the solution. It’s a lot more code but it works
It works a little different in that your REGEX must match the entire String, and it returns the first matching group (i.e. stuff in parens). Normally, you just need to match the part that you want from the String in other uses of REGEX.
Beyond that, the syntax for REGEX is exactly the same. .*#(.*) should work.
I don’t answer the question. You want everything after one or more “#” characters?
.*#+(.*)
You want to ignore cases where there is more than one “#”? Assuming that the string after the # is only letters and numbers)
.*#(\w*)
Instead of using “.” which means any character we use \w which only matches letter, numbers and underscore. So that expression won’t match anything in “OK ##FFF333”.
REGEX is a whole topic unto itself with whole books written about it.
In the MQTT Topic can come three (there are more but three for the colors) variations of this String:
OK #FFFFFF (for the first Color)
OK ##FFFFFF (for the second Color)
OK ###FFFFFF (for the third Color)
To requote myself since you appear to have ignored it:
You want to ignore cases where there is more than one “#”? Assuming that the string after the # is only letters and numbers)
.*#(\w*)
Instead of using “.” which means any character we use \w which only matches letter, numbers and underscore. So that expression won’t match anything in “OK ##FFF333”.
To match only the first variation:
.*#(\w*)
To matching only the second variation:
.*##(\w*)
To matching only the third variation:
.* ###(\w*)
As I said above, “.” matches any character, including “#”. That’s why you need to use \w so the stuff inside the () doesn’t match any extra # that may exist.
. : match any character
*: do the previous match 0 or more times
#: match exactly the character “#”
+: match the previous character one or more times
\w: match only letters and numbers and underscores
So .*#(\w*) means match any number of any character up to the first # you see, then match and return all the letters and numbers that follow the “#”. If you have more than one “#” the expression won’t match because “#” doesn’t get matched against with “\w”.
As I said, regular expressions are a whole topic unto themselves. Fully documenting them is outside the scope of openHAB. But there are tons of tutorials and guides on the web.