js remove html tags from string
JavaScript[Edit]
+
0
-
0
js remove html tags from string
1 2 3 4 5 6 7 8 9 10 11 12 13 14function removeHtmlTags(htmlString) { return htmlString.replace(/<>|<\/?[^>]+(>|$)/g, ''); } // Usage example: const header1 = '<h1>My header</h1>'; const paragraph = '<p>My paragraph</p>'; const fragment = '<>My fragment</>'; // React Fragments short syntax console.log(removeHtmlTags(header1)); // My header console.log(removeHtmlTags(paragraph)); // My paragraph console.log(removeHtmlTags(fragment)); // My fragment