2010-07-26 15 views
0

我有URL看起來像這樣...如何從一個url

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

從令牌

111978178853984提取字符串| 683b8096732be7fd725d3332- | m9lSbmoYhZ6Yut4OC3smY1fRf1E

557625434是身份證號碼。我怎樣才能從標記使用javascript提取Id號。

我很感激任何幫助。

謝謝。

回答

0

使用正則表達式,

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

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

說明:

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

試試這個:

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

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