How can I globally replace the | (pipe) symbol in a string? When I try to replace it with \"so|me|str|ing\".replace(/|/g, \'-\'), I get \"-s-
|
\"so|me|str|ing\".replace(/|/g, \'-\')
\"-s-
| has special meaning (A|B means "match A or B"), so you need to escape it:
A|B
"so|me|str|ing".replace(/\|/g, '-');