Yowza that's big. You can also use this more simplified regex:

(https?://)?www\.[^\s"]+

The concept is that an url will either start with http://, https:// or www.
(without the http prefix). This is our start anchor. After that we will
accept any character than is not a space character (space, tab, newline,
etc.) or a double quote (for urls embedded somewhere). This will work for
just about every url but is not exact. To be more exact you would have to
identify all of the legal characters in an url and match until you get to a
non-legal one.

(https?://)?www\.[][a-z0-9_$!&%?,#@'/.*+;:=~-]+

This does the same as above but checks if a character is not one of these:
][a-z0-9_$!&%?,#@'/.*+;:=~-
which are all legal in an url. The more specific you get in delimiting what
is the authority vs. what is the path vs. what is the query, it can be done
but...


On 6/20/07, Andy Matthews <[EMAIL PROTECTED]> wrote:
>
>
> ([A-Za-z][A-Za-z0-9+.-]{1,120}:[A-Za-z0-9/](([A-Za-z0-9$_.+!*,;/?:@&~=-])|%[
>
> A-Fa-f0-9]{2}){1,333}(#([a-zA-Z0-9][a-zA-Z0-9$_.+!*,;/?:@&~=%-]{0,1000}))?)
>
> That should do for you.
>
> :)
>
> -----Original Message-----
> From: Victor Moore [mailto:[EMAIL PROTECTED]
> Sent: Wednesday, June 20, 2007 11:43 AM
> To: CF-Talk
> Subject: Regex to convert url to link
>
> Hi,
>
> I get a text field form the db. Sometimes the text contains url like:
> http://www.abc.com (or just www.abc.com).
> Id is possible to write a regex to replace it to:
> <a href="http://www.abc.com";>http://www.abc.com</a>
>
> Thanks
> Victor
>
>
>
>
> 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
ColdFusion 8 beta – Build next generation applications today.
Free beta download on Labs
http://www.adobe.com/cfusion/entitlement/index.cfm?e=labs_adobecf8_beta

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:281662
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4

Reply via email to