Use Regex to extract second word from URL - Javascript RegExp

Javascript examples for RegExp:Match URL

Description

Use Regex to extract second word from URL

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   ww w  .  ja va  2  s.  co  m*/
var url = "/search/acid/all";
var regex = /.+?\/(.*?)\//g;
var match = regex.exec(url);
document.getElementById("second").innerHTML =match[1];
console.log(match[1]);
    }

      </script> 
   </head> 
   <body> 
      <span id="second"></span>  
   </body>
</html>

Related Tutorials