- The first Regular Expression Library on the Web!

Please support RegExLib Sponsors


Regular Expression Details

Title Test Find 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)!
Matches*)%3F%24&aq=f&aqi=&aql=&oq=&gs_rfai=&pbx=1&fp=ca05a7bb65e82229 |
htttp:// | | http://google.123 | http://google.commmmmm | http://123.456.789.1231
Author Rating: The rating for this expression. Xunnamius
Source My mind
Your Rating
Bad Good

Enter New Comment

Spammers suck - we apologize. Please enter the text shown below to enable your comment (not case sensitive - try as many times as you need to if the first ones are too hard):

Existing User Comments

Title: Lol
Name: Xunnamius
Date: 10/6/2012 4:24:52 PM
@ Colin I guess I'll just change the title to "Any URL/URN matcher," thanks. Nice mod!

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 ^((nntp|sftp|ftp(s)?|http(s)?|gopher|news|file|telnet):\/\/)?(([a-zA-Z0-9\._-]*([a-zA-Z0-9]\.[a-zA-Z0-9])[a-zA-Z]{1,6})|((([01]?\d{1,2}|2[0-4]\d|25[0-5])\.){3}([01]?\d{1,2}|2[0-4]\d|25[0-5])))(:\d+)?(\/[^:][^\s]*)?$

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.

Title: great
Name: scott
Date: 12/17/2010 3:03:52 AM
beautiful, just beautiful. finally. thanks.

Title: YES!
Name: Max
Date: 12/17/2010 3:00:24 AM
Signed up just go commend. JUST what I needed! Thanks!

Copyright © 2001-2018, | ASP.NET Tutorials