首页 > 代码库 > 今天早上 “百度知道”有人提问 正则 ,看着挺有意思的写了一个,写好后还没有回复,楼主就关闭了,哈哈自己好慢呀

今天早上 “百度知道”有人提问 正则 ,看着挺有意思的写了一个,写好后还没有回复,楼主就关闭了,哈哈自己好慢呀

在html中,
<div style="text-align: center; margin-top: 20px;"><img src="http://www.mamicode.com/sdsd.jpg" />
<a href="http://www.sdfs.com" target="_blank"> <img src="http://www.mamicode.com/sdsd.gif" /> </a></div>
<div style="text-align: center;">
<img width="100%" src="http://www.mamicode.com/sdsd.com/dff/newimg/2012/event/0720/J8/J8_gssd.jpg" /></div>
<p>
<img width="100%" src="http://www.mamicode.com/sdsd.com/xx-st/2014/07/04/904/0.jpg" /></p>
<p>
<img width="100%" src="http://www.mamicode.com/xx-st/2014/07/04/904/1.jpg" /></p></div>
<div style="padding:2px;" id="prd_dti_ftr_htm"></div>
<div style="padding:2px;" id="ctg_prd_dti_ftr_htm"></div>
<div style="padding:2px;" id="brd_prd_dti_ftr_htm"></div>
<div style="padding:2px;" id="brd_img_mdl_htm"><img width="100%" src="http://www.mamicode.com/sdsd.com/thejamy-new/images/fd/model/es_model.jpg" ></div>
</div></div> </div> </div>
我想提取img标签中有width="100%"属性,并且结尾是以[0-9]数字.jpg结尾的src地址

回复是 <img width="100%" src="[^"]+[\d]\.jpg"\s*/>
楼主自己做出来的
<img\b[^<>]*?\bsrc[\s\t\r\n]*=[\s\t\r\n]*[""‘]?[\s\t\r\n]*(?<imgUrl>[^\s\t\r\n""‘<>]*[0-9].jpg)[^<>]*?/?[\s\t\r\n]*>

   我写的: <img[^width]width="100%"[^src]src="http://www.mamicode.com/(?

[^"]*/\d.jpg[^"]*)"