I’m trying to get this regexp to return, and only return "flies a"
s = 'test <!-- flies are little birds --> end';
alert(s.match(/f(.*)a/));
Why does this return
flies a
lies
How can I make the f and a obligatory?
Thank you
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.
.matchreturns an array. The first element is the whole matched text and each other element is the content of a capture group. You have one capture group, so the second element is the text captured by it.Either remove the group or just ignore the other elements in the array. You have to access the first one in any case:
P.S.:
alertis a bad debugging tool, useconsole.logorconsole.dirinstead.