I have this string:
hello world hello world hello world hello
and I need to get the following:
hello world hello hello hello
If I use:
str = str.replace('world', '');
it only removes the first occurrence of world
in the above string.
How can I replace all the occurrences of it except the first one?
str.replace(/^(.*?world)|world/g, '$1')
(explanation) – Unpractical