views:

30

answers:

2

Hi,

I have url that looks like this...

http://www.example.com/accounts/?token=111978178853984|683b8096732be7fd725d3332-557626087|m9lSbmoYhZ6Yut4OC3smY1fRf1E.

from the token

111978178853984|683b8096732be7fd725d3332-557625434|m9lSbmoYhZ6Yut4OC3smY1fRf1E

557625434 is the id number. How can I extract the Id no from token using javascript.

I appreciate any help.

Thanks.

A: 

Use this regular expression,

/.*\-(\d+)|\w+$/

url.match(/.*\-(\d+)|\w+$/)[1] // 557626087

Explanation:

.*\     # everything before the dash
-       # -
(\d+)   # bunch of digits (this is the id)
|       # |
\w+$    # ending with a bunch of alphanumeric characters
Anurag
+2  A: 

try this:

var url = "http://www.example.com/accounts/?token=111978178853984|683b8096732be7fd725d3332-557626087|m9lSbmoYhZ6Yut4OC3smY1fRf1E.";

var splitString = url.split("|");
var idParts = splitString[1].split("-");
alert(idParts[1]);
Am