damdaman Posted June 2, 2010 Share Posted June 2, 2010 Hey everyone, new to regexp, still sifting through a pile of books. I'm using some public code to change plain text urls and images into html links, trying to modify it slightly to fit my needs. The problem is once I convert the images, I want the next preg_replace to convert all the links in the text that DON'T end in .gif, .jpg, or .jpeg. I've been playing around with the statement for awhile and can't seem to get it to work correctly. Any help would be appreciated. Here is the code I have: $imgs = "\.gif|\.jpg|\.jpeg"; $text = preg_replace('/(?<!S)((http(s?):\/\/)|(www.))+([\w.1-9\&=#?\-~%;\/]+(' . $imgs . '))/', '<img src="http$3://$4$5" border="0">', $text); $text = preg_replace('/(?<!S)((http(s?):\/\/)|(www.))+([\w.1-9\&=#?\-~%;\/]+)/', '<a href="http$3://$4$5" target="_blank">http$3://$4$5</a>', $text); I know I need to tag something on to the end of this: ...([\w.1-9\&=#?\-~%;\/]+)/' ...but like I said all my attempts have failed. Thanks in advance if someone can point me in the right direction.... Link to comment https://forums.phpfreaks.com/topic/203661-preg_replace-capturing-strings-that-dont-end-in/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.