extract path name from url

by Sreeraj Saseendran

HTML

<p>Click the button to display the path name of the current URL.</p>

<button onclick="myFunction()">Try it</button>

<p id="demo"></p>


<script>
function myFunction() {

var a = document.createElement('a');
a.href="https://vimeo.com/49835190";
  var x = a.pathname;
  document.getElementById("demo").innerHTML = x;
  var regExp3 = /\/(?:channels\/[^\/]+\/|groups\/[^\/]+\/videos\/|album\/[^\/]+\/video\/|video\/|)(\d+)(?:\/|\?|$)/;
                videoType = 'vimeo';
                if (a.pathname.match(regExp3)) {
                    document.getElementById("demo").innerHTML = a.pathname.match(regExp3)[1];
                }
}
</script>