1

How can I turn this "- | " into "-" with jQuery?

  .replace(/__-__ | /g, '__-__'

This also replaces the empty spaces

  .replace('__-__ | ', '__-__'

This only replaces the first time it occurs

2
  • this might help: stackoverflow.com/questions/11369182/… Commented Sep 7, 2012 at 8:13
  • 1
    You can't! .replace() is plain javascript? The first one uses a global regex, and the second one just matches the first occurence in a string. Commented Sep 7, 2012 at 8:13

2 Answers 2

2

Not sure why you're attempting this in jQuery. String replace is a javascript string method unless you're talking about replacing DOM elements.

input.replace(/- \|/g, '-_-');

See this example.

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

Comments

0

You answer helpt me out! :)

 .replace(/__-__ \|/g, '__-__')

This worked just great! Thanx!

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.