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.

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.

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'), '');

Comments

Your Answer

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.