1

I have a url...

/pensieve/q/22749623

I want to strip this url of everything but the tailing id and store it in a variable...

22749623

I am able to do this using a simple for loop...

var query_id = ''
for(var index = 12; index < query_url.length; index++){
    query_id += query_url[index];
}
var query_id = parseInt(query_id);

How do I do this with Javascript using regex?

I am finding a lot about how to do this in other languages, but not Javascript. I have checked StackOverflow and the rest of the internet to no avail.

Erik Åsland
  • 9,542
  • 10
  • 30
  • 58

1 Answers1

2

Just try this. (please see this)

var link="/pensieve/q/22749623";
var number = link.match(/\/([^\/]+)\/?$/)[1];
console.log(number);
Jed Fox
  • 2,979
  • 5
  • 28
  • 38
elreeda
  • 4,525
  • 2
  • 18
  • 45