THX
@ Christian-Me
i have not been able to get it to work properly in my existing function.
I have taken edje11 solution, because here it is always just a sign sign and it does not change.
let lines = msg.payload.split('\n'); // you could also do ')\n'
msg.payload=[];
lines.forEach ( line => {
let parts = line.split(/\||\(|\)/); // and here /\||\(/
if ( parts.length >= 3 ){
msg.payload.push({
IP : parts[0].trim(),
MAC: parts[1].trim(),
HW: parts[2].trim(),
})
}
})
return msg;
@UnborN the last match on line 4 of the string, will result in group being null, you need to add a conditional to lookout for a null match.
i didn't include the 4th line in the test as i considered that it was just there to imply that there were more lines
but yes, you are right, its good to check for null or length >= 3
(Edited the above post)