Serial device regex

Rait Lotamõis 3 years ago in Devices / Basic updated 3 years ago 6


I'm toying around with the Basic Serial device and having fun. Sending data is working without a hitch but reading is another matter.

When I'm trying to read data using regex, then instead of saving the regex capture group as the value, the entire data string or nothing, is stored as the Value.

For instance, this is what is coming in to the Serial port: 1;3;1;0;0;21.3

I'm interested in the last floating point number (21.3)

I have created 2 devices for reading data. One is a Double, the other is a String. Both are using this regex: 1;3;1;0;0;([\d+.\d+]*)

This is what the Double gets as a Value: 0

This is what the String gets as a Value: 1;3;1;0;0;21.3

The regex you used is not correct. Try (\d+\.\d+).

Tried this: 1;3;1;0;0;(\d+\.\d+) Unfortunately no change in behavior. the String gets the full data string as value, Double still gets 0 as Value

Just write (\d+\.\d+). Works for me with your string.

Unfortunately in that case it matches every piece of data that looks like this: int.int

I have a wide range of data coming in on the serial port:








So I need the regex to only get the value if the whole data packet matches.

I got it! Thanks for guiding me in the right direction, Jure. This is what gets me what I need: (?<=1;3;1;0;0;)(\d+\.\d+)

Looks like I was going about it the wrong way. I thought that we need to define a regex match and then a capture group inside it to get what we need. However, in reality the entire Regex we write is essentially a capture group. So when using helpers like this: https://regex101.com/ you need make sure that the "Full match" gets you the data you need, and ignore the individual capture groups.