how do i set up a negative reg expression match to pull out all the other links
Hi I have the following html and want to pull out all the other links that are not http://dont-match.co.uk
all the URLs to be matched are different all the ones not to be matched are the same hence I'm thinking along the lines of a negative match ie match all that are not 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 <开发者_如何学Ca href="http://dont-match.co.uk/">link text</a>
This is what i have so far:
/(<a href="http:\/\/[dont-match.co.uk]\/[^\"]*">([\d\D]*?)<\/a>)/
Use a negative lookahead (?!expression not to match)
:
preg_match_all('/(<a href="http:\/\/(?!dont-match\.co\.uk).*?\/[^"]*">(.*?)<\/a>)/', $str, $matches);
精彩评论