If I run this:
/([^\/]+)+/g.exec('/a/b/c/d');
I get this:
["a", "a"]
But if I run this:
'/a/b/c/d'.match(/([^\/]+)+/g);
Then I get the expected result of this:
["a", "b", "c", "d"]
What’s the difference?
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.
execwith a global regular expression is meant to be used in a loop, as it will still retrieve all matched subexpressions. So:String.matchdoes this for you and discards the captured groups.