亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

regex問題

請問下面html怎樣才可獲得12557637001?我想到的是開始為(?<=bc_4)

希望指點

<ul><li><span><a href="/cell-phones-service-plans-accessories/b/ref=dp_bc_1/135-5574408-5805717?ie=UTF8&node=2335752011">

? ? ? ? ? ? ? ? Cell Phones & Accessories

? ? ? ? ? ? </a></span></li><li><span>

? ? ? ? ? ? ??

? ? ? ? ?</span></li><li><span><a href="/cell-phone-accessories/b/ref=dp_bc_2/135-5574408-5805717?ie=UTF8&node=2407755011">

? ? ? ? ? ? ? ? Accessories

? ? ? ? ? ? </a></span></li><li><span>

? ? ? ? ? ? ??

? ? ? ? ?</span></li><li><span><a href="/chargers-charging-cables/b/ref=dp_bc_3/135-5574408-5805717?ie=UTF8&node=2407761011">

? ? ? ? ? ? ? ? Chargers & Power Adapters

? ? ? ? ? ? </a></span></li><li><span>

? ? ? ? ? ? ??

? ? ? ? ?</span></li><li><span><a href="/Cell-Phone-Wall-Chargers/b/ref=dp_bc_4/135-5574408-5805717?ie=UTF8&node=12557637011">

? ? ? ? ? ? ? ? ?Wall Chargers

? ? ? ? ? ? ?</a></span></li></ul>

正在回答

2 回答

$html=<<<HTML

? ? ? ? ? ? ? ? ? ? <ul><li><span><a href="/cell-phones-service-plans-accessories/b/ref=dp_bc_1/135-5574408-5805717?ie=UTF8&node=2335752011">


? ? ? ? ? ? ? ? Cell Phones & Accessories


? ? ? ? ? ? </a></span></li><li><span>


? ? ? ? ? ? ??


? ? ? ? ?</span></li><li><span><a href="/cell-phone-accessories/b/ref=dp_bc_2/135-5574408-5805717?ie=UTF8&node=2407755011">


? ? ? ? ? ? ? ? Accessories


? ? ? ? ? ? </a></span></li><li><span>


? ? ? ? ? ? ??


? ? ? ? ?</span></li><li><span><a href="/chargers-charging-cables/b/ref=dp_bc_3/135-5574408-5805717?ie=UTF8&node=2407761011">


? ? ? ? ? ? ? ? Chargers & Power Adapters


? ? ? ? ? ? </a></span></li><li><span>


? ? ? ? ? ? ??


? ? ? ? ?</span></li><li><span><a href="/Cell-Phone-Wall-Chargers/b/ref=dp_bc_4/135-5574408-5805717?ie=UTF8&node=12557637011">


? ? ? ? ? ? ? ? ?Wall Chargers


? ? ? ? ? ? ?</a></span></li></ul>

HTML;

? ? ? ? ? ? $pattern = '/&node=\d+">/';

? ? ? ? ? ? $matches = array();

? ? ? ? ? ? $res = preg_match_all($pattern,$html,$matches);

? ? ? ? ? ? $r = end($matches[0]);

? ? ? ? ? ? $r = substr($r,6,-2);

? ? ? ? ? ? echo $r;


0 回復 有任何疑惑可以回復我~

&node=\d{11}">

0 回復 有任何疑惑可以回復我~
#1

慕斯卡8255803 提問者

謝謝你的回答,但如果那最後的數字串不是固定11位就有機會配錯上面的(如果上面的有11位) 我想要的是配到的只要最後一個,我參考到一個negative lookahead的做法如下,好像行,請評論 (?<=node=)\d+(?!.*(?<=node=)\d+)
2018-03-15 回復 有任何疑惑可以回復我~
#2

飛哥傳說3 回復 慕斯卡8255803 提問者

PHP的preg_match_all($pattern,$subject,array &$matches)函數可以匹配所有,然后在$matches數組里獲取最后一個元素就可以了
2018-03-15 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號