Привет. У меня есть следующий HTML-код, и я хочу извлечь все другие ссылки, которые не http://dont-match.co.uk Все URL-адреса, которые должны быть сопоставлены, отличаются друг от друга. отрицательного совпадения, то есть совпадения со всеми, которые не http://dont-match.co.uk
http://dont-match.co.uk
<a href="http://match-this-url.com/">link text</a> some text <a href="http://match-this-diff-url.com/">link text</a> more text <a href="http://dont-match.co.uk/">link text</a> text <a href="http://match-this-different-url.com/">link text</a> text <a href="http://dont-match.co.uk/">link text</a>
Вот что у меня есть:
/(<a href="http:\/\/[dont-match.co.uk]\/[^\"]*">([\d\D]*?)<\/a>)/
Используйте негативный взгляд (?!expression not to match):
(?!expression not to match)
preg_match_all('/(<a href="http:\/\/(?!dont-match\.co\.uk).*?\/[^"]*">(.*?)<\/a>)/', $str, $matches);