Possible Duplicate:
Regex / Preg: No match, if found
I want to use preg_replace to replace some string if something in the string is NOT there. That is, if the substring is there, the string won’t be matched.
For example, if the string contains .png, it won’t find/match it.
example.com/image.png
Here, it will not find it because the string contains the line/substring .png.
example.com/image
Here, it will find it, because the string does not contain the line/substring .png anywhere.
For those who still does not get me.
$result = preg_replace("#http://(.*\S)[Something here that will not match the link if it finds the .png at last]#","<a href='\\1'>\\1</a>","Here is a link that should work http://example.com/; Here is a link that should NOT work http://example.com/image.png")
OK, I’m going out on a limb here.
First, you need a regex that’ll find a URL for you. Since you apparently want to find lots of invalid URLs, too, we’ll take a regex that simply considers any string of consecutive non-space character that contains a sequence
<letter>.<letter>:Then we can check that this sequence doesn’t end in
.png:Now you can use that for a replace operation, for example