http://msdn.microsoft.com/en-us/library/>>>
(\b(((((https?)|(ftps?))://|www\.))(((((\d)|(\d{2})|(([01](\d{2}))|(2[0-4](\d))|(25[0-5])))\.){3}((\d)|(\d{2})|(([01](\d{2}))|(2[0-4](\d))|(25[0-5]))))|(((([\w-_]|((%%)|(%[0-9A-Z]{2})))*([a-zA-Z])([\w-_]|((%%)|(%[0-9A-Z]{2})))*)\.)+(([\w-_]|((%%)|(%[0-9A-Z]{2})))*([a-zA-Z])([\w-_]|((%%)|(%[0-9A-Z]{2})))*)))/?)(((((((((%%)|(%[0-9A-Z]{2}))|[^ ()#?^&`{}|\[\]\x22<>\\])|([()]))}\.)+/)*)?((((((%%)|(%[0-9A-Z]{2}))|[^ ()#?^&`{}|\[\]\x22<>\\])|([()]))+\.)*((((%%)|(%[0-9A-Z]{2}))|[^ ()#?^&`{}|\[\]\x22<>\\]))+))?((([?#][^?# ]+)*)?))\b)Test and pattern builder program - you'll need the RegEx pattern builder download#37200 and topological sort download#37199
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.IO; using GregoryAdam.Base.Text.RegEx; namespace BaseTest { public class UrlTest { static void Main() { string pattern = RegexPatternBuilder.Construct(Definitions, "<url>"); Console.WriteLine(pattern); foreach ( string s in TestCases ) { Console.WriteLine("{0}", s); var matches = Regex.Matches(s, pattern, RegexOptions.Multiline); foreach( var match in matches) Console.WriteLine("found «{0}»", match); } Console.ReadLine(); } static string Definitions = @" <url> \b<server>(<segment>?(<query>?))\b <server> <serverIntro><serverBody>/? <serverIntro> (((https?)|(ftps?))://|www\.) <serverBody> <ip>|<serverWords> <ip> (<ipPart>\.){3}<ipPart> <ipPart> <ip1>|<ip2>|<ip3> <ip1> \d <ip2> \d{2} <ip3> ([01]<ip2>)|(2[0-4]<ip1>)|(25[0-5]) <serverWords> (<serverWord>\.)+<serverWord> <serverWord> <serverChar>*<alphaChar><serverChar>* <serverChar> [\w-_]|<CharEscaped> <alphaChar> [a-zA-Z] * <segment> <segmentBody>?<segmentTail> <segmentBody> ((<segmentChar>}\.)+/)* <segmentTail> (<segmentChar>+\.)*(<segmentCharNoParens>)+ <segmentCharNoParens> <CharEscaped>|[^ ()#?^&`{}|\[\]\x22<>\\] <CharEscaped> (%%)|(%[0-9A-Z]{2}) <segmentChar> <segmentCharNoParens>|<parens> <parens> [()] <query> ([?#][^?# ]+)* "; static string[] TestCases = { @"http://msdn.microsoft.com/en-us/library/", @"http://msdn.microsoft.com/en-us/library/aa172799SQL.80.aspx", @"(http://msdn.microsoft.com/en-us/library/aa172799SQL.80.aspx)", @" www.msdn.microsoft.com/en-us/library/aa139615.aspx ", @"http://msdn.microsoft.com/en-us/library/ aa172799SQL.80.a", @" (http://msdn.microsoft.com/en-us/library/aa172799(SQL.80).aspx) ", @"http://microsoft.com/test.asp?url=/example/abc.asp?frame=true#fragment ", @"http://192.168.10.254/test.asp?url=/example/abc.asp?frame=true#fragment ", @"wwww.192.168.10.254/test.asp?url=/example/abc.asp?frame=true#fragment ", @"www.microsoft.com/test.asp?url=/example/abc.asp?frame=true#fragment ", }; } }