here is the code
var str = 'a girl is reading a book!';
var reg = /\w*(?=ing\b)/g;
var res = str.match(reg);
console.log(res);
result is [“read”,””] in chrome.
I wanna ask why there is “” in the result.
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.
This is expected behaviour
First
readis captured since it is followed bying.Hereingis only matched..It is never included in the result.Now we are at the position after
readi.e we would be ati..here againingmatches(due to\w*) and it gives an empty result because there is nothing between read and ing.You can use
\w+(?=ing\b)to avoid the empty result