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.

1

1 Answer 1

2

Just try this. (please see this)

var link="/pensieve/q/22749623";
var number = link.match(/\/([^\/]+)\/?$/)[1];
console.log(number);

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.