Linking non-linked URLs

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
Cirdan
Forum Contributor
Posts: 144
Joined: Sat Nov 01, 2008 3:20 pm

Linking non-linked URLs

Post by Cirdan »

In my forum, I'd like to automatically link any URLs in the posts that are not already linked. I have this regex I found...

Code: Select all

@(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.\-]*(\-\?\S+)?)?)?)@
But I can't figure out how to make it ignore cases where there are quotes at the end. I have tried putting [^"\'] at various places within the regex, but that doesn't work. I also tried putting [\s\r\n], hoping it would find a blank space or new line and count that as a non-linked url, but that didn't work either. Any help would be much appreciated!
User avatar
andyhoneycutt
Forum Contributor
Posts: 468
Joined: Wed Aug 27, 2008 10:02 am
Location: Idaho Falls

Re: Linking non-linked URLs

Post by andyhoneycutt »

post an example of what you would like it to find, and what you would like it to avoid, if you would be so kind.
Cirdan
Forum Contributor
Posts: 144
Joined: Sat Nov 01, 2008 3:20 pm

Re: Linking non-linked URLs

Post by Cirdan »

Sure thing. For example if someone puts a url into a forum post like this: http://forums.devnetwork.net/index.php I want it to recognize that and automatically make a link out of it. However, if it finds a URL like this:<a href="http://myurl.com" >My URL</a> Then it should ignore it because it's already a link, or because it's a url for an <img> tag.
Post Reply