[Solved] javascript regex lookahead why abc match? [closed]


You need to handle new lines and you don’t need global search, because capturing must stop only before first abc appearance, so remove m and g flag and add singleline flag s:

const str = `test
abc abc`;

const result = str.match(/.*?(?=abc)/s);

console.log(result);

3

solved javascript regex lookahead why abc match? [closed]