Use Regex to Remove Specific Consecutive Duplicate Characters - Javascript String Operation

Javascript examples for String Operation:String Replace

Description

Use Regex to Remove Specific Consecutive Duplicate Characters

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   w w  w .  ja va 2s .  co  m*/
var oldString = "Aaabbcccccccd*def%testgGGhhhijkklmnoP\\122";
var filtered = oldString.replace(/[^\w\s]|(.)(?=\1)/gi, "");
document.write(filtered);
    });

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

Related Tutorials