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, '-');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With