$str = 'href="http://grego.com" href="httpxoobar" href="xxx" href="ZZZZZ"';
preg_match_all('/http:\/\/(?<!href=")([\s\S]+)"/', $str,$m);
print_r($m);
我正在尝试此代码。
我想要创建4个匹配项,我希望匹配所有href =“之后没有”http://“的内容,然后获取href =”(this)中的内容“(我'使用\ s \ S因为它可能包含新行)并且当它找到引号(“)时它停止并继续获取下一个(在这种情况下是在同一行),
在这个例子中它应该带来所有4个结果。
我该怎么做?感谢。
答案 0 :(得分:1)
你的事情有些混乱。
http://
作为比赛的一部分,尽管你写的是不想要匹配它,/s
选项来允许点匹配换行符,那就是说,你可能会逃避这个:
(?<=href=")(?!http://)[^"]+
我。即用PHP:
preg_match_all(
'%(?<=href=") # Assert position right after href="
(?!http://) # Assert that http:// is not right ahead
[^"]+ # Match one or more characters until the next "
%x',
$subject, $result, PREG_PATTERN_ORDER);
$result = $result[0];