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??
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Try adding the
g(global) flag to your pattern.Otherwise it would stop at the first match, in which case the return would be 1 (for the whole match), 1 (the control group).