Issue
Is there any way to strip HMTL tag with content in HTML
example :
const regexForStripHTML = /(<([^>]+)>)/gi
const text = "OCEP <sup>®</sup> water product"
const stripContent = text.replaceAll(regexForStripHTML, '')
output : 'OCEP ® water product'
I need to remove ®
also from a string
expected output
OCEP water product
Solution
Removing all HTML tags and the innerText can be done with the following snippet. The Regexp captures the opening tag’s name, then matches all content between the opening and closing tags, then uses the captured tag name to match the closing tag.
const regexForStripHTML = /<([^</> ]+)[^<>]*?>[^<>]*?<\/\1> */gi;
const text = "OCEP <sup>®</sup> water product";
const stripContent = text.replaceAll(regexForStripHTML, '');
console.log(text);
console.log(stripContent);
Answered By – phentnil
Answer Checked By – Cary Denson (BugsFixing Admin)