str = str.replace(new RegExp("abc", 'g'), "");
worked better for me than the above answers. so new RegExp("abc", 'g')
creates a RegExp what matches all occurence ('g'
flag) of the text ("abc"
). The second part is what gets replaced to, in your case empty string (""
).
str
is the string, and we have to override it, as replace(...)
just returns result, but not overrides. In some cases you might want to use that.