How to extract a string from a url
I have url that looks like this...
http://www.example.com/accounts/?token=111978178853984|683b8096732be7fd725d3332-557626087|m9lSbmoYhZ6Yut4OC3smY1fRf1E.
from the token
111978178853984|683b8096732be7fd725d3332-557625434|m9lSbmoYhZ6Yut4OC3smY1fRf1E
55762543开发者_JAVA技巧4 is the id number. How can I extract the Id no from token using javascript.
I appreciate any help.
Thanks.
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]);
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
精彩评论