I need some help with REGEX transformation in rules:
I execute in a bash script with the executecommandline command, receive either a negative integer (e.g. „-14“) or some text und a negative integer (e.g. „some text -14) and put in a string var.
Now I want to extract only the integer value (negativ or positiv doesn’t matter). I thought the easiest way to do that would be a REGEX transformation, but unfortunately I can’t get it work or rather I don’t know exactly which syntax is the right one.
var Number shortened = transform("REGEX", longString, ".*[0-9]")
and some variation of that.
Could someone give me a hint, to do it the right way?
I think you have the arguments in the wrong order. I think it goes:
transform("REGEX", expression, string)
At least that is my interpretation from the docs.
Thanks for your replay
That doesn’t work either. The result is always null (openhab log shows no error)
Simplify and try to get the string fragment you want, before trying to convert to number in same operation
Ok, now I’m able to catch the string fragment i want (I added the §-sign in the bash script to have a good point to split)
var String splitedString = longString.split("§")
var pieceofString = new String(splitedString.get(1))
Now I have the part of the String (e.g. -12) as a String, but I’m not able to convert this to a Number. So I need some help with that.
var newNumber = Integer::parseInt(pieceofString)