Jump to content
  • Advertisement
Sign in to follow this  
Jason Doucette

Suggestion: URLs clickable

This topic is 4116 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

It would need to cover both image and link tags, but more importantly, it needs to only capture opening-tags that haven't also already been closed. I could work out something like this, but I'm wondering whether anyone's already got some neat tricks for capturing "freetext" URLs in text that may contain regular HTML as well.

Share this post


Link to post
Share on other sites
Advertisement
I had forgotten about img tags as well. I see two possible options though (forgive me if the regex isnt correct, I'm making it up as I write this):

1) Something simple like

<(a|img)\s+[!>]*\s*(href|src)"?URL regex"?[!>]*>[!<]+<//(a|img)>

which matches <a href="URL">bla</a> but also matches <a src="URL">bla</a>

2) Two different regexes for img and a (those are the only tags the forum supports which have URLs, yes?)

Share this post


Link to post
Share on other sites
Yes, I think that works - but remember, the problem is to identify URLs that are not within those tags. Writing a regexp to pull a tag and its component parts is comparatively easy; I'm not sure if you can just 'invert' it somehow, I think you can't.

Share this post


Link to post
Share on other sites
You're right, I'm being completely backwards right now. You can probably safely ignore everything I've said or what I'm about to say. [smile]

I dont think you can invert it from within the regex itself but if you can identify the expressions you dont want to linkify then you can mark them in some way so that your later search-and-replace-to-linkify regex wont linkify. Maybe if you inserted some non-typeable character into the URL itself you could run the linkify regex and then remove that character afterwards.

Share this post


Link to post
Share on other sites
Ah, as a two-pass process? I guess that could be made to work, but there /must/ be a more elegant solution.

Hmm. Here are my testcases:

<a href="http://dont.link.this/">link but http://do.link.this/
<a href=http://dont.link.this/>link but http://do.link.this/
<img src="http://dont.link.this/">link but http://do.link.this/
<img src=http://dont.link.this/>link but http://do.link.this/
Your so-called "http://link.this/" domain...
My site=http://link.this/

Share this post


Link to post
Share on other sites
If you implement auto-linking URLs, you also need to provide a way to prevent it from being done - sometimes, somebody wants to talk about a "bad" site (whether it tries to install malware, is a scam, or is otherwise malicious) and wants to present the address but really doesn't want to link to it (lest somebody click on it without reading the text and have bad things done to them or their computer).

Share this post


Link to post
Share on other sites
Quote:
Original post by Oluseyi
Once you scratch the surface, it's not nearly as simple an issue as it initially may appear - not when done right.
Just use whatever is in the url tags, and replace with a link. What do TLDs have to do with it? It's a simple text replace. No different than bolding text.

Also, the original poster, you can make a clickable link by using the html code.
GOOGLE!

  GOOGLE!

Share this post


Link to post
Share on other sites
Quote:
Original post by Vampyre_Dark
Just use whatever is in the url tags, and replace with a link. What do TLDs have to do with it? It's a simple text replace. No different than bolding text.

It can be hard to tell because of the edits that the OP made, but the thread is about plain text links. Such as http://this.is.my.website. To make those clickable requires a regex, which is very different from bolding text.

Share this post


Link to post
Share on other sites
How about adding a url button to the posting... problem solved. Then you don't need a regex.

You could do a img button, a url button, and a you tube button, so the rick rolls are brought to us instead.

Share this post


Link to post
Share on other sites
Quote:
Original post by ViperG
How about adding a url button to the posting... problem solved. Then you don't need a regex.
Doesn't really fit the profile of 'automatic' linking, that. Not that it's a bad idea, just a separate one.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!