




正则取上述代码内src的值
image/ad1.gif
image/ad2.gif
image/ad3.gif
image/ad4.gif
image/ad5.gif
回复内容:





正则取上述代码内src的值
image/ad1.gif
image/ad2.gif
image/ad3.gif
image/ad4.gif
image/ad5.gif
获取src的值str,然后 str.match(/image(S*)gif/)[0]
$('img').each(function(index,item){
console.log(item.src.match(/image(S*)gif/)[0]);
})
/src=(?:pattern'|"|\['"]|\)?(.*?)(?:pattern'|"|\['"]|\)?sw/
我也不知道正不正确
//如果你的src中肯定不包含空格的话可以用这个简单的办法,通常是ok的
preg_match_all('/@@##@@
<p>这样得到的内容会包含单引号什么的,对于带有反斜线的单双引号先去掉反斜线,然后trim一下就行了,例如</p><div class="aritcle_card flexRow">
<div class="artcardd flexRow">
<a class="aritcle_card_img" href="/ai/1412" title="聚好用AI"><img
src="https://img.php.cn/upload/ai_manual/000/000/000/175680059460782.png" alt="聚好用AI" onerror="this.onerror='';this.src='/static/lhimages/moren/morentu.png'" ></a>
<div class="aritcle_card_info flexColumn">
<a href="/ai/1412" title="聚好用AI">聚好用AI</a>
<p>可免费AI绘图、AI音乐、AI视频创作,聚集全球顶级AI,一站式创意平台</p>
</div>
<a href="/ai/1412" title="聚好用AI" class="aritcle_card_btn flexRow flexcenter"><b></b><span>下载</span> </a>
</div>
</div>
<pre class="brush:php;toolbar:false;">foreach($_match[1] as str) {
$str = str_replace("\'", "'", $str);
$str = str_replace('\"', '"', $str);
echo trim($str, ''"');
}
大致这样,具体的自己调试吧。不太复杂的正则匹配优先考虑关键字符来排除结果,比如本例中的空格及制表符。
http://tool.oschina.net/regex/
@@##@@]*?src=\?["]?(.*?)["]?s[^>]*?>
此处应该有红包
$rule = '#@@##@@#';
你可以试试:在线正则表达式生成工具









