You are not Logged in
Would you like to Login or Register

Today is: Friday, 21 November, 2008
Check this months hot topics

URL Regular Expression

string pattern = @"((https?|ftp|gopher|telnet|file|notes|ms-help):((//)|(\\\\))+[\w\d:#@%/;$()~_?\+-=\\\.&]*)"
 
kick it on DotNetKicks.com del.icio.us digg Mister Wong YahooMyWeb Reddit Furl Spurl blogmarks
Paul Hayman Skype
Author : Paul Hayman
Published : Wednesday, 26 July, 2006

Paul is the COO of kwiboo ltd consultant and has more than a decade of IT consultancy experience. He has consulted for a number of blue chip companies and has been exposed to the folowing sectors: Utilities, Telecommunications, Insurance, Media, Investment Banking, Leisure, Legal, CRM, Pharmaceuticals, Interactive Gaming, Mobile Communications, Online Services. Paul is the COO and co-founder of kwiboo (http://www.kwiboo.com/) and is also the creator of GeekZilla.

Comments

Timoteo said:

Terrific. Thanks.

April 04, 2007 - 8:50 PM

Aung said:

Thanks

October 10, 2007 - 7:56 AM

Shadi Abu Hilal said:

Thanks man ;)

November 06, 2007 - 10:07 AM

Stephen G. said:

Excellent, this is a great help.

One suggestion though... be careful to escape the dash "-" character when using it in character class definitions []. Since a raw "-" is used to define a range (e.g., [A-Z]), you may want to escape the dash used in your Reg Ex.

The class [\w\d:#@%/;$()~_?\-=\\\.&] will unintentionally match all of the characters between and =. The following includes an escaped dash:

string pattern = "((https?|ftp|gopher|telnet|file|notes|ms-help):((//)|(\\\\))[\w\d:#%/;$()~_?\\-=\\\.&]*)"

July 14, 2008 - 5:41 PM

Michael said:

Don't use the regex from Stephen G.

Url's with "-" are splitted with this code.

August 24, 2008 - 10:56 AM

Peter said:

I thing it is not good, because when you specify url like this:

http://www.google.com:xxx (where :xxx represents port number) this must failed because xxx is not number (for port), but using this regex returns true.

October 24, 2008 - 8:54 AM

Yahya said:

Hellow Admin!!!!!!!!!!!

Thnks for presentation of bestandeveruseful site

October 25, 2008 - 7:26 AM

Add Comment

Enter your comment below and it will be submitted for moderation.

Your Name

Add Tag

Please enter tags for this article, seperated by semi-colon ;

View Tag's by : # articles | # views

More Publications

URL Regular Expression
Paul Hayman - 26/7/2006
IsGuid() (Regular Expression Guid Match)
Paul Hayman - 14/6/2006
IP Address regular expression
Paul Hayman - 4/8/2006
ISBN Number regular expression
Paul Hayman - 4/8/2006
Email Address Regular Expression
Paul Hayman - 26/7/2006