Hello,
I am trying to parse a string using regular expressions. This string can potentially have any number of non-alphanumeric characters acting as delimiters. These delimiters can also be grouped together. Here are some examples of the data:
00923:5342:123 --> I want to extract 00923, 5342 and 123 into an array
08765::764375 --> parse this as 08765 and 764375 into an array
3246//672354//23458 --> parse as 3246, 672354 and 23458
23564-73654 --> etc
I'm using the following code:
var ids = str.match(/\w*/g);
But it just returns the first token from each line and ignores the rest. So with the above data I'm only getting back 00923, 08765, 3246 and 23564 into the first element of the "ids" array.
I've also tried an "inverse" approach using the split method like so:
var ids = str.split(/\W*/g);
and I just get the same result - the first token only.
My test code looks like this ('str' contains a string read in from a file):
var ids = str.match(/\w*/g);
//var ids = str.split(/\W*/g);
task.logmsg("the length of the array is " + ids.length);
for (i = 0; i < ids.length; i++) {
task.logmsg("ids=[" + i + "]=" + ids[i]);
}
I can confirm that ids.length is returning 1 (??)
The 'task' object comes from a separate library and the 'logmsg' method just writes to the console.
My reptilian brain is struggling with reg exps. This shouldn't be difficult to do, but I just can't get it to work.
If anyone out there can lend some assistance, it would be greatly appreciated.
Thanks,
JD