Ultimate URL URN Regex
Finally, an expression that can reliably match any valid URL/URN! Future proof against vanity TLDs, doesn't require a schema, can parse IPv4s with or without port, can parse regular URLs with/without port, can accept extra baggage at the end, and, with a slight modification (a la ^$ and changing the final rule around a bit) this can be used to find and activate URLs in bodies of text safely and reliably. Have fun (tell me if it could be improved)!
http://www.google.com/#sclient=psy&hl=en&q=this+is+a+google+serach+%5E((Csftp)%3A%2F%2F)%3F((%5Ba-zA-Z0-9%5C._-%5D%2B%5C.%5Ba-zA-Z%5D%7B2%2C7%7D)%7C((%5B0-9%5D%7B1%2C3%7D%5C.)%7B3%7D%5B0-9%5D%7B1%2C3%7D))(%3A%5Cd%2B)%3F(%2F%5Ba-zA-Z0-9%5C%26amp%3B%25_%5C.%2F-~-%23%5D*)%3F%24&aq=f&aqi=&aql=&oq=&gs_rfai=&pbx=1&fp=ca05a7bb65e82229 | http://192.168.1.1:5649
htttp://google.com | http://google-.com | http://google.123 | http://google.commmmmm | http://123.456.789.1231
Date: 10/6/2012 4:24:52 PM
@ Colin I guess I'll just change the title to "Any URL/URN matcher," thanks.
Title: Worked (with a lilttle modification)
Name: Francisco Cittadini
Date: 6/14/2012 1:42:32 PM
Great, it helped me a lot, thanks! However I modified it like the following so that it doesn't accept 255.255.255.256.
Title: Not quite working
Name: Colin Griffith
Date: 2/3/2012 10:37:20 PM
That doesn't quite work. Look at my regex here:
Many of the URIs that are in the official standard URI documentation as examples will not match yours (especially the telephone one), whereas my regular expression I had to test extensively to get it to match them. Also, some of the example non-matches you show here, would actually match as a valid URI. Maybe not valid URLs (no such thing as .commmmmmmm), but it'd be a valid URI.
Date: 12/17/2010 3:03:52 AM
beautiful, just beautiful. finally. thanks.
Date: 12/17/2010 3:00:24 AM
Signed up just go commend. JUST what I needed! Thanks!