Regex and which programming language is used in rules/foo.rules config files?

  • Platform information:
    • Hardware: raspberry pi 4 with 2GB ram
    • OS: openhabian
    • Java Runtime Environment: I don’t know
    • openHAB version: I don’t know, I installed openhabian in september 2019

Hi. I’m using only config files, not webinterface.
I’m writing rules. I have no problems with simple things like when Item foo changed
and myitem.state.
But now i have a string myString from a mqtt broker far away, not mine.
The string is full of “space” at the beginning, between words, at the end.
I want to delete the “spaces” at the beginning and the end and reduce all multiple spaces to only one.
the regex ist in perl
s/^ +//
s/ +$//
s/ +/ /g

now three questions

  1. how can I delete the spaces?
  2. how can I split the String in more strings, one for each wort
  3. which programming language is used in the rules? and where can I find the full documentation of the functions?

thanks very much (and sorry for my bad english)
Antonio
PS: is somewhere a forum in german or italian or french? or can I write in these tongue too, here?

Two german forums:

https://openhabforum.de/

The rules language is a DSL built with xtend, so there is a tendency to java.

Thanks for the Link to the german forum (here absolutly in english? or are other languages allowed? like german, french, italian)?

the the second anword: what is DSL? and, more important, where is the documentation with all the functions? like substr(), split(), regex(), legth of a word, etc?

This forum is english only, sorry.

DSL -> Domain Specific Language, so there are some parts builtin to fit for openHAB.

There is some documentation out there. And there are plenty of postings about this :wink: like this one: Xtend api documentation

In Rules

MyStringItem.state.toString.trim()java string 

Since you have regular expressions defined, you can use the REGEX transform. Just be aware that tin OH, the REGEX must match the full String, not just the line you are after. The first capture group will be returned.

  1. In a Rule:

    MyStringItem.state.toString.split(" ")

  2. You have access to core Java and a lot of stuff is Java (all the String stuff discussed above is just basic Java). The structure of the Rules themselves are a Domain Specific Language. Udo provided where to get started on that syntax.

NOTE: This is just one way to define Rules in OH. There is the option to use Jython, JavaScript, or Groovy as well if that suits you better.