2

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
0

2 Answers 2

1

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
Sign up to request clarification or add additional context in comments.

Comments

1

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'), '');
answered Apr 23, 2013 at 10:11

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.