Remove duplicate forward slashes from the URL via regex - Javascript RegExp

Javascript examples for RegExp:Match URL

Description

Remove duplicate forward slashes from the URL via regex

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  .j  ava 2  s  .  c om


var str = 'http://localhost//example/author/admin///';
var clean_url = str.replace(/([^:])(\/\/+)/g, '$1/');
console.log(clean_url);


    }

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

Related Tutorials