(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

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


(A bit tongue-in-cheek for a second, here.)

Have you seen a good regex for validating URLs lately?  It's *nasty*.  See:

http://www.foad.org/~abigail/Perl/url2.html

Or, if you're the type of person who skips to the end, the regex can be
found here:

http://www.foad.org/~abigail/Perl/url3.regex

It's a bit more than 7500 characters long.  :)  However, I think that it
would make an *excellent* test of CF's regex engine.  Of course you'd have
to translate from perl-style regexs to CF-style regexs, but it should be
possible.

-R

-----Original Message-----
From: Jennifer [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, August 01, 2000 1:31 PM
To: [EMAIL PROTECTED]
Subject: Re: Functions in Cold Fusion


How about IsURL?

At 01:10 PM 8/1/00 -0400, you wrote:
>OK, I need some community input here. For my article on custom functions,
>I've written one for IsEmail and IsPhone. Can people send me a few others
to
>'add in'. I'd like the article to have a few pre-built functions that can
be
>used right off the bat. The only limits are that they must be built using
>functions in CF. No tags. For example, IsPhone uses this code:
>REFindNoCase('([0-9]{3}[-_. /]?)?[0-9]{3}[-_. /]?[0-9]{4}', number)

----------------------------------------------------------------------------
--
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.

------------------------------------------------------------------------------
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