开发者

Regex javascript

i Guys I need some help with some Regular expression:

here is the string:

<div style="width:477px;" id="__ss_8468630"><strong style="dis开发者_开发问答play:block;margin:12px 0 4px;"><a rel="nofollow" target="_blank" href="http://www.slideshare.net/Account/title" title="&#x002019;s DDM SaaS Antivirus Patch Management Solution">DDM SaaS Antivirus Patch Management Solution</a></strong> <div style="padding:5px 0 12px;"> View more documents from <a rel="nofollow" target="_blank" href="http://www.slideshare.net/account">Account</a> </div> </div>

and I need to get just the id number .

ex. output:

8468630

thanks everyone


No regEx necessary, you can just do a simple string replace.

element.id.replace('__ss_',''); // => '8468630'


"__ss_8468630".match(/[\d\.]+/g); // --> [8468630]


This will get those digits. Although this will break if the # of digits changes.

\d{7}


Being e the div element you could use this

var n = e.id.match(/__ss_(\d+)/)[1];

As match returns an array containing the whole match in the position 0 (__ss_8468630) and the matching groups in its same position. Group 1 "(\d+)" (8468630)


You can do the following:

var num = element.id.replace(/\D*/g, '' )
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜