Home >Backend Development >PHP Tutorial >:这个a标签的正则怎么写?

:这个a标签的正则怎么写?

WBOY
WBOYOriginal
2016-06-23 13:32:271194browse

情感剧场:爱情公寓精装版
剧情

只想匹配class为black的超链接,不想匹配 class="font12-orange"

请问大神们,正则怎么写?


回复讨论(解决方案)

$str = <<<EOF<a href="http://jq.tvsou.com/introhtml/14/index_1468.htm" target="_blank" class="black">情感剧场:爱情公寓精装版</a><a href="http://jq.tvsou.com/introhtml/730/index_73026.htm" target="_blank" class="font12-orange">剧情</a>EOF;preg_match('/<a href="([^"]+?)"[^>]+?class="black">(.+?)<\/a>/i',$str,$m);echo "<pre class="brush:php;toolbar:false">";print_r($m);echo "
";/*Array(    [0] => 情感剧场:爱情公寓精装版    [1] => http://jq.tvsou.com/introhtml/14/index_1468.htm    [2] => 情感剧场:爱情公寓精装版)*/

$zz='/(.*)?/';

$str =<<<FDIPZONE <a href="http://jq.tvsou.com/introhtml/14/index_1468.htm" target="_blank" class="black">情感剧场:爱情公寓精装版</a><a href="http://jq.tvsou.com/introhtml/730/index_73026.htm" target="_blank" class="font12-orange">剧情</a> <a href="http://jq.tvsou.com/introhtml/14/index_1468.htm" target="_blank" class="black">情感剧场:爱情公寓精装版</a><a href="http://jq.tvsou.com/introhtml/730/index_73026.htm" target="_blank" class="font12-orange">剧情</a> <a href="http://jq.tvsou.com/introhtml/14/index_1468.htm" target="_blank" class="black">情感剧场:爱情公寓精装版</a><a href="http://jq.tvsou.com/introhtml/730/index_73026.htm" target="_blank" class="font12-orange">剧情</a>FDIPZONE;preg_match_all('/<a.*?href="(.*?)".*?class=\"font12-orange\"/si',$str, $matches); echo "<pre class="brush:php;toolbar:false">";print_r($matches[1]);echo "
";

正在学习正则表达式,学习了!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn