开发者

How can i get value with javascript regular expressions

开发者 https://www.devze.com 2023-01-16 09:24 出处:网络
i have following text http://www.mydomain.com/#!/account/?id=17 and i am getting # with window.location.href which is gi开发者_开发百科ving me

i have following text

http://www.mydomain.com/#!/account/?id=17

and i am getting # with window.location.href which is gi开发者_开发百科ving me

#!/account/?id=17

now i want to extract that id value with preg_match or any regular expression because that id value is dynamic... actually i am loading data with jquery ajax...please let me know the exact expression for getting value of id...


Try this:

"#!/account/?id=17".match(/id=(.*)/)[1]

EDIT

var result = window.location.href.match(/id=(.*)/);
  • match returns an array with two positions:
    • result[0] = all matched string ("id=17")
    • result[1] = first group match ("17")
0

精彩评论

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

关注公众号