Reputation: 2982
I'm writing this simple regexp in Javascript
str = "1-2-3-456789";
re = /(\d+)/;
found = str.match(re);
alert(found);
I'm waiting for an array with 1,2,3,456789 but the result is 1,1 Why??
Upvotes: 1
Views: 48
Reputation: 175098
Try adding the g
(global) flag to your pattern.
re = /(\d+)/g;
Otherwise it would stop at the first match, in which case the return would be 1 (for the whole match), 1 (the control group).
Upvotes: 2