First word in a sentence

  • Platform information:
    • Hardware: raspi 3
    • OS: openhabian
    • Java Runtime Environment: 11.0.10 (Zulu11.45+27-CA)
    • openHAB version: 3.0.1

I need a regular expression for the first word in a sentence. Can anybody help me please?

What have you tried? Does the text have more than one line of text?

How do you define the first word ? Does it include numbers as well ?

I want to extract “Bioabfall” from “Bioabfall 2-Rad-Behaelter 02-woechentl.” There is just one line of text. The first word does not contain numbers.

It would be quicker to just google your question. And it would be also helpful for all of us to share informations about what exactly you already did to solve the problem for yourself, like Rich mentioned.


Google is your friend…
Here is on of the first search results…

1 Like

You beat my by a couple of seconds…:stuck_out_tongue_winking_eye:

1 Like

Unfortunately both regular expressions do not work:

I only get an empty string.

What is the result of


I also get an empty string.

Please try


Tried with a regexbuilder and gives „This“ as a result of „This is a test“

I never tire of saying The openHAB REGEX Transformation Service is not REGEX.
@rlkoshak often says “you must match the whole string”, that usually involves *

Unfortunately it’s the same: empty string.

I have installed RegEx transformation. Do I have to install something else too?

Never used REGEX, sorry for misleading…

This does not help me. What’s the correct expression?

Oh, I didn’t realise it was “Write my code for me”.

I find it easier to experiment in rules first

val rawstring = "   The quick brown fox
jumps over the lazy dog"
var results = transform("REGEX", "^(\\S*)[\\s]+.*", rawstring)
logInfo("test", " first word " + results)
logInfo("test", " count " + results.length)


I have tried your code as a rule and everything works fine. Thank you.

Unfortunately the regular expression does not work, when I edit the channels and add a link to an item:

I still get an empty string. Do I need a different syntax here? Can anybody help me? Where can I get some information?

You probably don’t need the double escapes in that context. They were to allow handling of the regex string in a rule context.

1 Like

Hooray! ^(\S*)[\s]+.* works! Thank you very much!