I have
var removeNotification = " (F)";
listVariable = listVariable.replace(removeNotification, '');
This works partially, but it only finds the first " (F)" within the string and replaces it to "". There are about many others I need to change as well.
What I need is a way to find ALL matches and replace it.
asked Apr 23, 2013 at 9:53
Okky
10.5k16 gold badges78 silver badges123 bronze badges
2 Answers 2
Try this:
var removeNotification = /\s\(\F\)/g; // "g" means "global"
listVariable = listVariable.replace(removeNotification, '');
console.log(listVariable)
This will replace ALL matches, not just the first one.
answered Apr 23, 2013 at 10:09
palaѕн
74.2k17 gold badges123 silver badges140 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
You could do it this way if removeNotification cannot be hard coded:
// escape regular expression special characters
var escaped = removeNotification.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&')
// remove all matches
listVariable = listVariable.replace(new RegExp(escaped, 'g'), '');
Comments
lang-js