0

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

1

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.

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

Comments

0

You can easily achieve this with combination of indexOf, lastIndexOf, and substring js methods... documentation

Comments

0

It is hard to tell the general case from your example, but let me try:

str = str.replace(/\|([^|]+)-Foo\|/, '$1');

Comments

0

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.

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.