valoricDe / MultiRegExp2

Get all matches of a regexp with corresponding start and end positions
GNU General Public License v3.0
12 stars 5 forks source link

wrong capture index #1

Closed qjebbs closed 7 years ago

qjebbs commented 7 years ago

Please look into this code:

let str = "aaaaaaaaa";
let reg = /((a{2})a(\2))/ig;
let mreg = new MultiRegExp2(reg);
let matches = mreg.execForAllGroups(str, true);
for (let m of matches) {
    console.log(m.match, m.start, m.end);
}

output:

aaaaa 0 5
aa 0 2
aa 3 5

expected:

aaaaa 0 4
aa 0 1
aa 3 4
qjebbs commented 7 years ago

I realized that you may intentionally make the end index point to next start index, so I close this issue now.

valoricDe commented 7 years ago

Yeah it is intentional. As I think it would be weird to have a match like {"match":"x","start":1,"end":1}