let data = `<?xml version="1.0" encoding="UTF-8"?>
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mn>1</mn>
<mo>=</mo>
<semantics>
<mrow>
<mn>2</mn>
</mrow>
<annotation encoding="text/plain">2</annotation>
</semantics>
<mspace linebreak="newline" />
<mn>2</mn>
<mo>=</mo>
<semantics>
<mrow>
<mn>3</mn>
</mrow>
<annotation encoding="text/plain">3</annotation>
</semantics>
</math>`
const regex = /<annotation\s*[^>]*>(.|\n)*?<\/annotation>/
while(regex.test(data)) {
data = data.replace(regex, '')
}
console.log(data)
After replacing the annotation tags with empty string, I want to delete that empty line.