var regex = RegExp(w, 'g'); var s2 = s1.replace(regex, '');
str.split(before).join(after)
You could try to escape those special characters but that is potentially error prone.
For an arbitrary w, one approach is something kind of awful like:
let s2 = s1; while (s2.includes(w)) { s2 = s2.replace(w, '') }