when I try the following it doesn't work: str.replace("| stuff", "")
But if I remove the PIPE it does? str.replace("stuff", "")
Why doesn't the JS function allow for the PIPE | ? What can I do to do a replace that includes a pipe?
when I try the following it doesn't work: str.replace("| stuff", "")
But if I remove the PIPE it does? str.replace("stuff", "")
Why doesn't the JS function allow for the PIPE | ? What can I do to do a replace that includes a pipe?
Because .replace accepts a RegExp, and | is a special character in RegExp. You need to escape it.
For example, use str.replace(/\|/g, "") to remove every | character.
No, it should be working, unless you use /| stuff/ or RegExp("| stuff") instead of "| stuff"
"xyz| stuff".replace("| stuff", ""); //returns xyz
str.replace("| stuff", "") should work but will only replace the first occurrence. If you want to replace all of them, try a using a regex like str.replace(/\|\sstuff/g, "")
str.replace(/\| stuff/g, ""), but the \s makes it work for any whitespace character