I'm brand new to JavaScript an quite a novice to coding in general, but I'm trying to self teach myself as much as possible.
I am trying to extract data from a variable string. The original string is in the following format:
CAMERA NAME(NUM): North West Rd(D1)
CAMERA NAME(NUM): Even Longer Camera Name(D2)
CAMERA NAME(NUM): Cam13(D13)
All I want is the string within the final brackets. I was hoping to have a split function which I could say something along the lines of
str.split(CAMERA NAME(NUM): **variable Characters and length** (,);
But I'm unsure how to account for the variable text and length in between (NUM): and (
I'd be very grateful for any suggestion, Thanks!
P.s - I'm currently using this method which works, but I'd like to know how to account for variable strings for future projects, as this will almost certainly come up again.
Thank you. Luke
var txt = msg.payload;
var array = [];
var newTxt = txt.split('(');
//node.warn(newTxt);
for (var i = 1; i < newTxt.length; i++) {
array.push(newTxt[i].split(')')[0]);
}
//node.warn(array[1]);
msg.payload = array[1];
return msg;
^.+\((.+)\)$