Q:

Unable to get numbers from window.location.search

I am using the following code in my JS file:
var match = window.location.search.match(/(\d*)/);
this.room = (match) ? decodeURIComponent(match) : 0;

And I am trying to just get the numbers from my URL. For example, in www.myurl.com/streams228, I just want to get the 228.
The issue I am getting is it is just returning %2, nothing else, or 0.

A:

Try the following:

var url ="www.myurl.com/streams228"
var match = url.match(/([\d]+)/g);
console.log(match[0]);

