Search href and match URL with regex, and open part of url - Javascript RegExp

Javascript examples for RegExp:Match URL

Description

Search href and match URL with regex, and open part of 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">
function OpenMyPage(hyperlink) {/*from   www.j a v  a2  s . c  o m*/
   var source = hyperlink.attributes.href.value; 
   var pattern = new RegExp("(\\d+)$"); 
   source.match(pattern); 
   console.log(RegExp.$1);
}

      </script> 
   </head> 
   <body> 
      <a href="http://www.mydomain.com/ID=25645" onclick="OpenMyPage(this); return false;">Click HyperLink</a>  
   </body>
</html>

Related Tutorials