How can I get the content of an HTML comment using JavaScript? I tried this:
function getContent(comment) {
return comment
.replaceAll("<!--", "")
.replaceAll("-->", "")
}
// Expected output: "hello world"
console.log(getContent("<!--hello world-->"));
// Expected output: "some text", but the real content of the comment is "some <!--text"
console.log(getContent("<!--some <!--text-->"));
But when the edge case where there is additional <!--'s happens, the additional <!--'s get removed. How can I fix this.