Javascript examples for RegExp:Match URL
Use Regex to extract second word from URL
<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>