1

How to use javascript to get the following url - the value of id?

URL: http://www.url/id/2721/John

I would get the following values:

2721 and John
Corbin
33.6k7 gold badges74 silver badges79 bronze badges
asked May 7, 2012 at 21:24
4

2 Answers 2

3

Use .split("/") to separate the URL into pieces, then read the values.

answered May 7, 2012 at 21:27
Sign up to request clarification or add additional context in comments.

Comments

0

Use .match(re):

var r = "http://www.url/id/2721/John".match('\/id\/(\\d+)/([^/]+)');

The value v[1] will be 2721 and r[2] will be John.

kapex
30.2k6 gold badges117 silver badges128 bronze badges
answered May 7, 2012 at 21:37

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.