开发者

How to extract a string from a url

开发者 https://www.devze.com 2023-01-09 01:41 出处:网络
I have url that looks like this... http://www.example.com/accounts/?token=111978178853984|683b8096732be7fd725d3332-557626087|m9lSbmoYhZ6Yut4OC3smY1fRf1E.

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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号