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-o-|-m-e-|-s-t-r-|-i-n-g-"
|
"so|me|str|ing".replace(/|/g, '-')
"-s-o-|-m-e-|-s-t-r-|-i-n-g-"
| has special meaning (A|B means "match A or B"), so you need to escape it:
A|B
"so|me|str|ing".replace(/|/g, '-');
1.4m articles
1.4m replys
5 comments
57.0k users