I've been working on a regexp, that would parse a date from the format of
3d 4m 5y
to an array, so that I could do some manipulations with it.
I have written a regexp like this:
((\d+)([d,m,y]))
What this returns is
["3d", "3d", "3", "d"]
When I believe it should be returning
["3d", "3d", "3", "d","4m","4","m"]
for the string
3d4m
It is implemented in my code like this:
c=console;
myregexp=/((\d+)([d,m,y]))/g;
//myregexp = new RegExp(regexstring);
c.log(myregexp.exec($("#dateInterval").val()));
right now I'm only logging the data, but I do think, that something is wrong here.
execwill probably not group them for you recursively. Are you sure you aren't aiming forconsole.log('3d 4m 5y'.match(myregexp));?[dmy]is what you want. Otherwise, the comma would also be matched.