Reputation:
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!
Upvotes: 1
Views: 102
Reputation: 43169
You may use
^\++|\++$
JavaScript
:
string.replace(/^\++|\++$/g, "");
Upvotes: 2