aragon1337 Posted July 20, 2007 Share Posted July 20, 2007 The following regular expression matches an image tags with anchor around it, preg_match_all ('/((?:<\s*a\s*(?:.*)\s*>)<\s*img\s*(?:.*)\s*\/>(?:<\/\s*a\s*>))/i', $news_text, $pattern1, PREG_PATTERN_ORDER); Now i want another expression that matches ONLY the image tags that DOES NOT have anchor tag around it. For example the following are stored in a variable, $str = '<img src="hello.jpg" title="sadsad" /> <a href="one.html"><img src="hi.jpg" title="asdat" /></a>' I want to match ONLY <img src="hello.jpg" title="sadsad" /> not the other. Please help. Quote Link to comment Share on other sites More sharing options...
Wildbug Posted July 20, 2007 Share Posted July 20, 2007 Another thread addressed a very similar issue this week. Try: /(?<!>)(?>\s*<img\s+.*?>\s*)(?!<\/a>)/i Quote Link to comment Share on other sites More sharing options...
aragon1337 Posted July 20, 2007 Author Share Posted July 20, 2007 Worked fine. Thank you. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.