It would also help to add position matching characters such as ^ and $. This
would prevent additional information from being passed along the URL. As
this regex stands additional information could be passed either before or
after a matched URL, without throwing any errors. I also added the ability
to accept an optional 's' for HTTPS URLs. I'm thinking about the
username/password part but, it will take more than a second to whip out.


----------

(^https?://((((([[:alnum:]](([[:alnum:]]|-)*[[:alnum:]])?)\.)*([[:alpha:]]((
[[:
alnum:]]|-)*[[:alnum:]])?))|(([[:digit:]]+)(\.([[:digit:]]+)){3}))(:([[:digi
t:]]+))?)(/(((([a-zA-Z0-9$\-_.+!*'(),~]|(%[[:xdigit:]]{2}))|[;:@&=])*)(/((([
a-zA-Z0-9$\-_.+!*'(),]|(%[[:xdigit:]]{2}))|[;:@&=])*))*)(\?((([a-zA-Z0-9$\-_
.+!*'(),]|(%[[:xdigit:]]{2}))|[;:@&=])*))?)?$)

----------


Steve


-----Original Message-----
From: Rick Osborne [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, August 01, 2000 3:06 PM
To: [EMAIL PROTECTED]
Subject: RE: Functions in Cold Fusion


(Because I know that if I didn't take the challenge then someone else
would...)

The perl regex for *HTTP URLs only* is:

(?:http://(?:(?:(?:(?:(?:[a-zA-Z\d](?:(?:[a-zA-Z\d]|-)*[a-zA-Z\d])?)\.)*(?:[
a-zA-Z](?:(?:[a-zA-Z\d]|-)*[a-zA-Z\d])?))|(?:(?:\d+)(?:\.(?:\d+)){3}))(?::(?
:\d+))?)(?:/(?:(?:(?:(?:[a-zA-Z\d$\-_.+!*'(),]|(?:%[a-fA-F\d]{2}))|[;:@&=])*
)(?:/(?:(?:(?:[a-zA-Z\d$\-_.+!*'(),]|(?:%[a-fA-F\d]{2}))|[;:@&=])*))*)(?:\?(
?:(?:(?:[a-zA-Z\d$\-_.+!*'(),]|(?:%[a-fA-F\d]{2}))|[;:@&=])*))?)?)

CF doesn't support the "?:" operator (don't back-ref) or the "\d" escape
sequence (digit), so those needed to be taken out.  I wanted to make it a
bit more readable so I translated to POSIX classes where appropriate.  The
resulatant CF-style regex is:

(http://((((([[:alnum:]](([[:alnum:]]|-)*[[:alnum:]])?)\.)*([[:alpha:]](([[:
alnum:]]|-)*[[:alnum:]])?))|(([[:digit:]]+)(\.([[:digit:]]+)){3}))(:([[:digi
t:]]+))?)(/(((([a-zA-Z0-9$\-_.+!*'(),~]|(%[[:xdigit:]]{2}))|[;:@&=])*)(/((([
a-zA-Z0-9$\-_.+!*'(),]|(%[[:xdigit:]]{2}))|[;:@&=])*))*)(\?((([a-zA-Z0-9$\-_
.+!*'(),]|(%[[:xdigit:]]{2}))|[;:@&=])*))?)?)

Since the entire thing is wrapped in parens, you can then use it in
REReplace and backref it with \1.  This leads to interesting uses:

IsURL(foo) = REFind(URLRegEx,foo)
URLify(foo) = REReplace(foo,URLRegEx,'<A HREF="\1">\1</A>',"ALL")

Notes:
- This doesn't take into account user/password info in the URL, like
(http://user:[EMAIL PROTECTED]/).  I'm pretty sure this is legal, but it may not
be.
- This is for HTTP URLs only.  If you want others and don't have the RegEx
skills, let me know and I can whip something up for you.
- I added in the tilde character for path information, as while it isn't
technically legal it is used quite a bit.

I did test this and it worked like a champ.  Go CF!  :)

-Rick

------------------------------------------------------------------------------
Archives: http://www.mail-archive.com/[email protected]/
To Unsubscribe visit 
http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/cf_talk or send a 
message to [EMAIL PROTECTED] with 'unsubscribe' in the body.

Reply via email to