Regular expression in javascript

javascript, regex

Solution

This is expected behaviour

First `read` is captured since it is followed by `ing`.Here `ing` is only matched..It is never included in the result.

Now we are at the position after `read` i.e we would be at `i`..here again `ing` matches(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

Problem

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.

Original source