-1

I have a string, let's say:

var str = "    "

To replace this with an empty string I'm using this regex:

str.replace(/^(&nbsp;|<br>)+/, '');

This is removing only the first nbsp;. The remaining two are still there. Can anyone please help me to remove all the occurrences of nbsp; and <br> from the string?

4

1 Answer 1

3

Use the g flag ("global") within your regular expression to replace all matches rather than the first:

str.replace(/ <your pattern here> /g, "");
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.