Find the last occurrence and replace it with the given string
str = 'we need to replace THIS, not the first THIS, but the last THIS, and change THIS to other text'
I need smth like str.replace(someRegExp, 'yeah, we did it') converted to 'we need to replace THIS, not the first THIS, but the last THIS, and change yeah, we did it to other text'
Need to change the last 'word' occurrence with the 2 argument of replace func. We cant rely on the text around the word. The thing i tried -
str.replace(/(.*)THIS/,'$1yeah, we did it');
But this method is bad cuz of algorithmic complexity and memory usage... Then i tried lazy search, but this one is changing all the words in string. Is there any method to do lazy search from the end of the string with only 1 replace? I haven't found any reverse thing in js