Splitting strings with node-red

3.9k Views Asked by At

I am trying to split the following llap message with node red:

a--A02+1023-

so I end up with the integers after the '+' sign. Sometimes there are three numbers with a '-' for the final character. eg. a--A02+982--

once i have this 3 or four digit number I can extrapolate relevant sensor values

Ive managed it with python but the ways of node red are new to me.

Many thanks

1

There are 1 best solutions below

1
On

Pass the message through a function node and use a regular expression

var regExp = /.*\+(\d+)-/;
var results = regExp.exec(msg.payload);
msg.payload = results[1];

return msg;