Remove HTML Tags in Javascript with Regex

Try this, noting that the grammar of HTML is too complex for regular expressions to be correct 100% of the time:

var regex = /(<([^>]+)>)/ig
,   body = "<p>test</p>"
,   result = body.replace(regex, "");

console.log(result);

If you’re willing to use a library such as jQuery, you could simply do this:

console.log($('<p>test</p>').text());

Leave a Comment