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-"
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-"
|
has special meaning (A|B
means "match A or B"), so you need to escape it:
"so|me|str|ing".replace(/|/g, '-');