Fri, 17 May 2024


How to strip HTML tags from a string with a simple regular expression using JavaScript?

By: Peter, NetArt Media
Wed, 16 March 2022

<HTML>
<HEAD>
<TITLE> Regular Expressions: stripping HTML tags </TITLE>
</HEAD>
<BODY>
<SCRIPT LANGUAGE="JavaScript">
var htstring = '<p align="Left"><b>Hello</b> <I>World</I></p>';
var stripped = htstring.replace(/(<([^>]+)>)/ig,"");
with (document)

{

write ('Original string:' + htstring + '<br>');
write ('Stripped string:<br><br>' + stripped);

}

</SCRIPT>
</BODY>
</HTML>


Category: Javascript
Share this post:



See All Scripts






Subscribe for our newsletter

Receive the latest blog posts direct in your mailbox