Use regex to strip out both HTML tags and their contents from a string - Javascript RegExp

Javascript examples for RegExp:Match HTML

Description

Use regex to strip out both HTML tags and their contents from a string

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){/*from   www  . j av  a 2  s.  c  o m*/
    var subject = "foo <div>>bar</div>> baz";
    var result = subject.replace(/^(.*?)(?:<.*>)(.*?)$/ig, "$1>$2");
    console.log(result);
    }

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials