1

I need to remove the "+" chars in some strings.

I'm using this regex:

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

The problem is when i have strings like: "+++++test+string+++" it obviously gets transformed to teststring and the correct result should be test+string.

So what i need is to figure out a regex that removes the "+" char, only at the start and end of the string.

Thanks!

1 Answer 1

2

You may use

^\++|\++$

See a demo on regex101.com.


In JavaScript:

string.replace(/^\++|\++$/g, "");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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