regex replace paragraphs which only has less than 3 characters - Javascript String Operation

Javascript examples for String Operation:String Replace

Description

regex replace paragraphs which only has less than 3 characters

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
   </head> 
   <body> 
      <div id="foo"> 
         <p>hello</p> 
         <p>This paragraph not to be removed</p> 
         <p>12</p> 
         <p>1</p> 
         <p></p> 
         <p>thi</p> 
         <p>this is a test</p> 
         <p>stays</p> 
      </div> 
      <script type="text/javascript">
var e = document.getElementById("foo");
e.innerHTML = e.innerHTML.replace(/<p>.{0,2}<\/p>/g,"");

      </script>  
   </body>/* www .  j a  v a 2  s  .c om*/
</html>

Related Tutorials