RegExLib.com - The first Regular Expression Library on the Web!

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find RFC URL
Expression
(([\w]+:)?//)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?
Description
A pretty decent URL matching expression. I've followed most RFC guidelines, so it'll match most anything ya throw at it (And wont match what it's not supposed to). If you see any problems with it, please email me so I can make the appropriate changes :)
Matches
http://www.domain.com | http://domain.com | http://domain.com | https://domain.com | https://sub.domain-name.com:8080 | http://domain.com/dir%201/dir_2/program.ext?var1=x&var2=my%20value | domain.com/index.html#bookmark
Non-Matches
Normal Text. | http://a.com | http://www.domain-.com
Author Rating: Not yet rated. r4cc00n
Source
Your Rating
Bad Good

Enter New Comment

Title
 
Name
 
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: www.test.museum
Name: Vijay
Date: 9/25/2013 1:35:35 AM
Comment:
Doesn't work with "www.test.museum" .


Title: www.test.museum
Name: Vijay
Date: 9/25/2013 1:34:46 AM
Comment:
Doesn't work with "www.test.museum" .


Title: www.test.museum
Name: Vijay
Date: 9/25/2013 1:34:10 AM
Comment:
Doesn't work with "www.test.museum" .


Title: Doesn't work with www.adrouinaventure.c.la
Name: Gavin
Date: 6/21/2009 11:18:50 PM
Comment:
I like this regular expression, but have found an issue with it... It doesn't work with legitimate *.c.la domains because of the single char (c in this case) being present. Had a quick play to try and resolve the issue, but my regular expression skills aren't so great I'm afraid :(


Title: False Positive
Name: Dirq
Date: 11/7/2007 4:06:13 PM
Comment:
The RegEx matched: FC1.2AH4


Title: Additions
Name: John
Date: 10/14/2007 10:36:11 PM
Comment:
I have found that it needed a bit of tweaking. The following url was not recognized: http://java.sun.com/j2se/1.4.2/docs/api/java/lang/StringBuffer.html#indexOf(java.lang.String,%20int) This is because of the used brackets and the comma. Because this url IS valid I added the ',' ')' '(' to the regex. Also I added ^ and $ at the beginning and end respectively. Nice job this is the best basis I have found to base something on so far. My more complete regex now is: "^(([\w]+:)?//)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\,\(\)\d\w]|%[a-fA-f\d]{2,2})*)?$" without the quotes.


Title: equals sign in url
Name: Ben
Date: 8/27/2007 10:51:55 PM
Comment:
Thanks for the regex, it's very helpful. I noticed it's not matching the following: http://www.example.com/VGEwMTM3fDY2Mw==/NTI1NzozOjM It matches up until the equals sign. Is this URL not RFC compliant?


Title: x.com
Name: James
Date: 8/20/2007 6:33:13 AM
Comment:
Doesn't match "www.x.com"


Title: If http(s):// is required, and user:pass@ is not to be allowed...
Name: bcire
Date: 4/30/2007 8:36:40 AM
Comment:
...try this... ((https?):\/\/){1}(([\d\w]|%[a-fA-f\d]{2,2})+(([\d\w]|%[a-fA-f\d]{2,2})+)?)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?


Title: Matches e-mails
Name: Jonathon
Date: 2/25/2007 11:50:33 AM
Comment:
@Anonymous, works fine in preg_replace() under PHP 5.2.1 for me. @r4cc00n, your regex matches e-mail addresses like test@example.com. Not sure if that was your intention, but probably isn't for most people; should at least put that in your description.


Title: doesn't work in PHP
Name: Anonymous
Date: 2/23/2007 12:56:32 AM
Comment:
This particular expression throws an Unknown modifier error while using the preg_match() function.


Title: IDNA missing
Name: André
Date: 1/3/2007 11:03:41 AM
Comment:
Hi, you really wrote a fantastic regex for URL-validation but IDNA´s are missing, which includes at least following characters: á à ă â å ä ã ą ā æ ć ĉ č ċ ç ď đ é è ĕ ê ě ë ė ę ē ğ ĝ ġ ģ ĥ ħ í ì ĭ î ï ĩ į ī ı ĵ ķ ĺ ľ ļ ł ń ň ñ ņ ŋ ó ò ŏ ô ö ő õ ø ō œ ĸ ŕ ř ŗ ś ŝ š ş ť ţ ŧ ú ù ŭ û ů ü ű ũ ų ū ŵ ý ŷ ÿ ź ž ż ð þ maybe you´ll update your regex? :)


Title: against RFC url
Name: Wine
Date: 6/2/2006 3:13:24 AM
Comment:
Wine SOS. Powerful Wine Support Formula. http://www.winesos.com/wine.html


Copyright © 2001-2019, RegexAdvice.com | ASP.NET Tutorials