0

i want to replace all occurrences of "+" in a string with a space

    Query = Query.replace(new RegExp("+", "g")," ");

But it raises error "SyntaxError: invalid quantifier" on above line What i am doing wrong here?

1

4 Answers 4

1

Query.replace(/+/g,' ');

Will replace any occurrences of + with space.

Sign up to request clarification or add additional context in comments.

Comments

0

How about

Query.replace(/\+/g, "");

You will need to backslash the +

Comments

0

Try this..

Query = Query .replace(new RegExp("\\+", "g")," ");

Comments

0

try this : Query = Query.replace(/\+/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.