JasonLewis Posted October 14, 2008 Share Posted October 14, 2008 Okay, some may remember, some may not. Basically I have this pattern, provided by effigy. preg_match_all('% ( (?> ### Protocol or start. (?: (??:https?|ftp)://) | www\. ) ### Body: gobble everything except [/url] (??!\[/url\]|\[/img\]).)+ ### Avoid ending punctuation. (?<!\s\p{P}) ) ### Not followed by an url end. (?!\[/url\]|\[/img\]) ) %x',$str,$matches); It works, brilliantly. But now I've found another flaw in it. Basically, what it does is links any unlinked links in a string. Like what this forum does. But now it's not working if I provide a link like this: www.google.com < link that Basically anything followed by a space/new line won't work. I don't know why it didn't happen last time I was testing it but now it's not working again. If you have a space it will link everything after the space. It's really odd, I cannot for the life of my figure out the problem. " Thanks all! Link to comment https://forums.phpfreaks.com/topic/128348-solved-more-problems-with-that-url-regex/ Share on other sites More sharing options...
effigy Posted October 14, 2008 Share Posted October 14, 2008 At some point the . was \S to only capture non-whitespace. I can't figure out why this changed in the old posts, but that's what you're after. I've restored this and cleaned up the img addition with alternation: preg_match_all('% ( (?> ### Protocol or start. (?: (??:https?|ftp)://) | www\. ) ### Body: gobble non-space, [/url], [/img] (??!\[/(?:url|img)\])\S)+ ### Avoid ending punctuation. (?<!\s\p{P}) ) ### Not followed by an url/img end. (?!\[/(?:url|img)\]) ) %x', $str, $matches); Link to comment https://forums.phpfreaks.com/topic/128348-solved-more-problems-with-that-url-regex/#findComment-664948 Share on other sites More sharing options...
JasonLewis Posted October 15, 2008 Author Share Posted October 15, 2008 You beauty! You're awesome effigy! Cheers! Link to comment https://forums.phpfreaks.com/topic/128348-solved-more-problems-with-that-url-regex/#findComment-665877 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.