I'm using a regex negative lookahead in JavaScript to replace the last occurrence of a string within a string using regex matching.
Heres a snippet of my code:
var str = 'abc abc abc'
var regex1 = /abc(?!.*?abc)/
var regex2 = /abc(?!.*abc)/
var ematch1 = regex1.exec(str);
var ematch2 = regex2.exec(str);
console.log(ematch1, ematch1.index);
console.log(ematch2, ematch2.index);
Both these regexes - regex1 and regex2 - are getting identical results. Which is preferred and why? Or is a totally different approach better?