I have a string representing HTML, and I am trying to use str.replace(regex, "") to replace all instances of regex in a string with an empty string. The substring that I need to replace begins with <!--[if
and ends with <![endif]-->
, and there are multiple occurrences in the string.
Here is the regex that I tried:
const regex = /^(<!--\[if).*(<!\[endif]-->)$/g
To me, this says "a string that begins with <!--[if
and ends with <![endif]-->
and has any number of characters in between, while escaping the opening square brackets and using the global flag." That's what I want, so I can use str.replace:
const newString = oldString.replace(regex, "")
I'm not catching any matches. I can only think that I'm missing something about the grouping of the sequence of characters at the beginning and end.