I have this string here:
<br><br>|Me-Foo|: htht
What i want to do is to transform it to this:
<br><br>Me: htht
basically to change only the part inside the two "|", remembering tha the "Foo" might change with another name, like "john" or whatever. .. But I don't know how to!? A quick solution anyone?
Thanks
4 Answers 4
You can remove that with...
str = str.replace(/\|(\w+)-\w+\|/, '1ドル');
You didn't specify the constraints of what appears between the pipes. If word characters (\w) aren't flexible enough, adjust as required.
Comments
You can easily achieve this with combination of indexOf, lastIndexOf, and substring js methods... documentation
Comments
It is hard to tell the general case from your example, but let me try:
str = str.replace(/\|([^|]+)-Foo\|/, '1ドル');
Comments
Is this helpful?
theString = theString.replace(/\|(.+)-.+\|/, "1ドル");
There are several answers given. This one replaces
"anything*& 45|anything8 \$-().?anything| 90fanything"
with
"anything*& 45anything8 \$ 90fanything"
The best answer depends on what could possibly be in between the pipes.