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. Link to comment https://forums.phpfreaks.com/topic/60976-solved-regular-expression-image-without-anchor-around-it/ 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 Link to comment https://forums.phpfreaks.com/topic/60976-solved-regular-expression-image-without-anchor-around-it/#findComment-303506 Share on other sites More sharing options...
aragon1337 Posted July 20, 2007 Author Share Posted July 20, 2007 Worked fine. Thank you. Link to comment https://forums.phpfreaks.com/topic/60976-solved-regular-expression-image-without-anchor-around-it/#findComment-303575 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.