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

Mackelito
  • 4,213
  • 5
  • 39
  • 78
  • this might help: http://stackoverflow.com/questions/11369182/how-to-replace-elements-attr-href-with-each-strip-url – Barlas Apaydin Sep 07 '12 at 08: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. – adeneo Sep 07 '12 at 08:13

2 Answers2

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.

Neil
  • 5,762
  • 24
  • 36
0

You answer helpt me out! :)

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

This worked just great! Thanx!

Mackelito
  • 4,213
  • 5
  • 39
  • 78