If I have a string that contains </custom-tag>
, how can I use replace to find all occurrences of this tag in a string and replace it with "" , for example mystr.replace(/</constant>/g,"")
will not work.
You need to escape the /
so that it isn't interpreted as the end of the regex.
mystr.replace(/<\/constant>/g, "")
Of course, if your search is a constant expression, as it is here, you can use the following technique to perform a global replace without regular expressions:
mystr.split("</constant>").join("")
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