[Closed] Split Input String using Regex

I have sensor data from a serial device coming in like this:

RX 02 FD 10 00 00 00 00 00 04 69 .

The “RX” denotes the start of new sensor data, the period marks the end.

The binding is configured like this:

String  sensorData  "Sensor-Rx [%s]"  <text>  { serial="COM1@115200,REGEX(\\s?RX\\s{1}(.*?)\\s?\\.)" }

Usually the item is updated as expected. With the example above the log output is

sensorData state updated to 02 FD 10 00 00 00 00 00 04 69

Now the Problem:
Sometimes sensor data is received in short intervals. Then the log output shows that the item contains data of two sensor messages:

sensorData state updated to 0C 65 00 EA 00 59 71 00 23 69.RX 02 FD 10 00 00 00 00 00 04 69

But rather than combining multiple sensor messages into a single item update I’d much prefer multiple item updates for each sensor message.

Checking my regex here only the first sensor message is returned.
So how do I get the regex to do the same here?
I expect that doing this would result in two updates of the sensorData item which is the desired behaviour.


Note:
The regex tester doesn’t like the double backslashes which are required in openHAB so the following expression was used with the regex tester:

\s?RX\s{1}(.*?)\s?\.

Also the global modifier /g was disabled.
Enabling it returns the same as the openHAB regex.
So maybe the question must be
How is the global modifier enabled and disabled in an openHAB regex?

Sorry for the bad formatting of the text. Someof the line breaks are ignored.

Unfortunately I didn’t get this to work as expected.

So I’m using this workaround:

  • Pass complete serial string to item sensorData
  • Use rule to seperate the sensor messages using this regex: \s?RX\s{1}(.*?)\s?\.
  • For each match extract the data bytes using this regex: [0-9A-F]{2}

So essentially this uses nested regex expressions. Each of those uses the approach described here:
https://community.openhab.org/t/solved-rules-matching-a-repeated-pattern-with-regex/27735