Mackelito
Mackelito

Reputation: 4421

jquery .replace

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

Upvotes: 1

Views: 609

Answers (2)

Mackelito
Mackelito

Reputation: 4421

You answer helpt me out! :)

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

This worked just great! Thanx!

Upvotes: 0

Neil
Neil

Reputation: 5782

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.

Upvotes: 2

Related Questions