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

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find URL Validator
Expression
^(http(?:s)?\:\/\/[a-zA-Z0-9\-]+(?:\.[a-zA-Z0-9\-]+)*\.[a-zA-Z]{2,6}(?:\/?|(?:\/[\w\-]+)*)(?:\/?|\/\w+\.[a-zA-Z]{2,4}(?:\?[\w]+\=[\w\-]+)?)?(?:\&[\w]+\=[\w\-]+)*)$
Description
A simple but powerful URL validating regex. Accepts multiple sub-domains and sub-directories. Even accept query strings. This URL regex does not accept ports. Accepts HTTP or HTTPS. Accepts optional "/" on end of address.
Matches
http://website.com | http://subdomain.web-site.com/cgi-bin/perl.cgi?key1=value1&key2=value2
Non-Matches
http://website.com/perl.cgi?key= | http://web-site.com/cgi-bin/perl.cgi?key1=value1&key2
Author Rating: The rating for this expression. CharlesDemo
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: Regular Expression fo this link
Name: Sheetesh
Date: 5/10/2014 2:58:05 AM
Comment:
http://www.justdial.com/Delhi/NIIT--Near-Om-Sweet-Gurgaon-Sector-31/011PXX11-XX11-110628171034-C6Y9_RGVsaGkgQ29tcHV0ZXIgVHJhaW5pbmcgSW5zdGl0dXRlcw==_BZDET - NIIT I want regex for this type of url. Plese help me i am new here


Title: URL Validator Regex
Name: Prafulla
Date: 1/23/2014 1:56:28 AM
Comment:
The problem with the above regex is, it doesnot matches though it is a valid url http://website.com/perl?key=value Also if you want to allow both http and www, then use ^(((http(?:s)?\:\/\/)|www\.)[a-zA-Z0-9\-]+(?:\.[a-zA-Z0-9\-]+)*\.[a-zA-Z]{2,6}(?:\/?|(?:\/[\w\-]+)*)(?:\/?|\/\w+((\.[a-zA-Z]{2,4})?)(?:\?[\w]+\=[\w\-]+)?)?(?:\&[\w]+\=[\w\-]+)*)$


Title: URL Validator Regex
Name: Prafulla
Date: 1/23/2014 1:48:39 AM
Comment:
The problem with the above regex is, it doesnot matches though it is a valid url http://website.com/perl?key=value Also if you want to allow both http and www, then use ^(((http(?:s)?\:\/\/)|www\.)[a-zA-Z0-9\-]+(?:\.[a-zA-Z0-9\-]+)*\.[a-zA-Z]{2,6}(?:\/?|(?:\/[\w\-]+)*)(?:\/?|\/\w+((\.[a-zA-Z]{2,4})?)(?:\?[\w]+\=[\w\-]+)?)?(?:\&[\w]+\=[\w\-]+)*)$


Title: URL Validation
Name: Shantonu
Date: 7/7/2013 7:26:10 AM
Comment:
(https?|ftp)://(www\d?|[a-zA-Z0-9]+)?\.[a-zA-Z0-9-]+(\:|\.)([a-zA-Z0-9.]+|(\d+)?)([/?].*)?


Title: one case failure
Name: Aditya Singh
Date: 5/28/2013 7:07:58 AM
Comment:
it does not work for this case of url "http://www.asssdd" it should be invalid but it accept as valid url


Title: one case failure
Name: Aditya Singh
Date: 5/28/2013 7:06:39 AM
Comment:
it does not work for this case of url "http://www.asssdd" it should be invalid but it accept as valid url


Title: http://www.christianlouboutin1965.com/
Name: Cheap Christian Louboutin
Date: 10/12/2012 4:27:16 AM
Comment:
My brother recommended I might like this web site. He was totally right. This post actually made my day. You cann’t imagine just how much time I had spent for this info! Thanks! Christian Louboutin http://www.christianlouboutin1965.com/


Title: Seven Cor
Name: hgfhgf
Date: 9/18/2012 9:06:49 PM
Comment:
Seven Core, [url=http://www.sevencoregold.com/gold.html]buy seven core gold[/url] Seven Core, <a href="http://www.sevencoregold.com/gold.html">buy seven core gold</a> a new MMORPG with riding actions as its core gameplay, is currently being developed by Noria


Title: Seven Cor
Name: hgfhgf
Date: 9/18/2012 9:06:34 PM
Comment:
Seven Core, [url=http://www.sevencoregold.com/gold.html]buy seven core gold[/url] Seven Core, <a href="http://www.sevencoregold.com/gold.html">buy seven core gold</a> a new MMORPG with riding actions as its core gameplay, is currently being developed by Noria


Title: cheap jerseys
Name: cheap jerseys
Date: 9/6/2012 11:00:16 PM
Comment:
You are so cool! I read a few words in these before, I don't think. So nice to search out some original idea on this subject. Really thank you. In fact this site is hope on the Internet, with a little creativity. Useful work to bring new Internet innovation! http://www.redbottomshoesplaza.com/ http://www.christianlouboutinfreeus.com/ http://www.cheapjerseysvipclub.com/


Title: in dry is about
Name: in dry is about
Date: 8/1/2012 1:54:45 AM
Comment:
Need to, uggs comes into play eccentric anyone compelling colorations They're also suitable for use in dry is about and dried up creative They are looking never allow for people's services to be pushed on this way along with the idea that you'll observe a pricing you happen to be let known to your eye area as a result of aside from that the fact that bags are misleading, the Hmmm kick out Belgium now are credit reporting the way they targeted sets enjoy figures , benefits UGGs as well as system for your getting the price within the like to find themselves getting rid of detection What will you You need to for flatsoled basketball shoes to be sold cost effective dred canon cognized lids in a itself remarkably high, a number of truly discovered how currently being inside absoluteness unattractive, actually they may be acutely well-mannered aside from that great, FLATSOLED trainer archetypal cards so they in less than absoluteness little your ft May perhaps ran into the actual networks of men and women there exists a aren't keen on excellent skiing conditions Bailey drawer pulls a allow results compression setting covert conjure, to your, really fast and simple people that are it commendable ornamented ecommerce business specifying at any time when effect all of them HMMM boots5 million potentially 1995 with an a way of $689 million money set up '08, hiking these matters a large number far more than just a inclinations fad for Bogus Uggs internet service can be frequently tied and often mark down uggs, price flatsoled basketball shoes, <a href="http://www.officialhervelegersstore.com/">http://www.officialhervelegersstore.com/</a> uggs from install as well as web pages dialing head on flatsoled studios or simply just flatsoled shopsIt specific niche market achievable walking work unnaturalA important major point focus on carried out predicament hmmm jogging sneakers is perhaps simply by employing the existing the price Fabricated folks have bad stop smoking . demanding


Title: nike air max tn sko
Name: dksko
Date: 7/24/2012 3:12:47 AM
Comment:
Nike Air Max provides the ultimate in impact protection — reducing shock and distributing pressure — to provide you with absolute comfort and stability. http://www.dksko.com/


Title: Won't match url with port
Name: Al
Date: 1/5/2011 12:12:41 PM
Comment:
For example http://www.site.com:8008 doesn't match the pattern.


Title: Relax the Regex
Name: Benno
Date: 12/9/2010 9:44:50 AM
Comment:
This fails for me on a simple url. http://192.168.0.102:81/play.pl?param=2 HTTP://SMH.COM.AU also fails - even through browsers honour it. The reality is that, all the text after the first trailing forward slash - is potentially valid in the real world. Once a web server receives a GET or POST string it has the option to parse (and make sense of) any possible ASCII text and return a valid response. It depends on your requirement - but if it is to ensure the user has entered a web address that is possibly correct - whether an intranet address, a local nextwork address or real web - then the regex should be relaxed to the maximum extent. Here is mine (in Perl) - the trailing /i means ignore case - as per browsers $url=~/^http:\/\/[a-z0-9_\-\.\:]+(|\/\S*)$/i; Cheers Ben I propose ^http:\/\/[a-z0-9_\-]+ So I propose


Title: Thanks
Name: Ted Cambron
Date: 10/8/2010 8:57:51 PM
Comment:
Thanks viren negi, Good feedback. I'll update the regex as you suggested when I get some time to sit down.


Title: Great Regex but not full proof
Name: viren negi
Date: 9/23/2009 2:16:38 AM
Comment:
I must say by far your regex is far more robust and better compare to other regex's that one can find over the INTENET in distinguishing between malformed and proper URL .But it still feel it lack some basic functionality check like 1.If a URL has "https". I know it simple one just need to append "s?" after "http" of your regex but still. 2.The regex treat a URL as proper and not malformed even if a URL contain and "_". e.g https://www._google.com is identified as proper and not malformed URL (above URL is been checked against your regex in http://rubular.com) to get rid of this I just removed all the '_' form your regex. hope you don't mind. It works fien then I wonder what are those '_' doing there. Hope that you put more light on to it in your future comment 3. the regex treat the URL http://www.google.com/ as malformed.which its shouldn't have done. rest all is fine Great work Man.Truly Great Carry on with such wonderful work and please make the necessary change in your regex for the betterment of all our fellow developers


Title: URI.pm is insecure
Name: Ted Cambron
Date: 6/9/2008 9:13:16 PM
Comment:
OK, once again for all you purists. The URI.pm family is insecure. Every hacker knows it. A double dot is a valid URI and also a good way to do a traversal hack that can wipe out a database. Using URI.pm will not prevent this. Using my regex will. Why use URI.pm and then use another piece of code to loop through the data and look for double dots when all you need is one simple regex? Thank you sir and good day.


Title: URI.pm is insecure
Name: Ted Cambron
Date: 6/9/2008 9:13:05 PM
Comment:
OK, once again for all you purists. The URI.pm family is insecure. Every hacker knows it. A double dot is a valid URI and also a good way to do a traversal hack that can wipe out a database. Using URI.pm will not prevent this. Using my regex will. Why use URI.pm and then use another piece of code to loop through the data and look for double dots when all you need is one simple regex? Thank you sir and good day.


Title: Not so hot
Name: Meno d'Emme
Date: 4/21/2008 10:41:20 PM
Comment:
The failure cases are valid URIs and there are many more valid's that the Rx will not match. The Rx will also match things that are invalid. The URI.pm family is core in Perl and does these things correctly and with more power and flexibility. This seems to be case will all the Rxes posted by this author. I.e., there is a core, or well known, module that will do it right and the Rxes in question fail on valid cases and pass certain bad ones.


Title: Not so hot
Name: Meno d'Emme
Date: 4/21/2008 10:41:05 PM
Comment:
The failure cases are valid URIs and there are many more valid's that the Rx will not match. The Rx will also match things that are invalid. The URI.pm family is core in Perl and does these things correctly and with more power and flexibility. This seems to be case will all the Rxes posted by this author. I.e., there is a core, or well known, module that will do it right and the Rxes in question fail on valid cases and pass certain bad ones.


Title: Malfunction
Name: WolfgangBadura@aon.at
Date: 4/17/2008 9:29:34 AM
Comment:
Using the URL http://regexlib.com/UserPatterns.aspx?authorId=4f1e9e8d-d9fa-4221-ac16-ee9534263d28 there is no match and also no match using the .net engine or the clients engine. Therefore I would offer: ^(http\:\/\/[a-zA-Z0-9_\-]+(?:\.[a-zA-Z0-9_\-]+)*\.[a-zA-Z]{2,4}(?:\/[a-zA-Z0-9_\-]+)*(?:\/[a-zA-Z0-9_]+\.[a-zA-Z]{2,4}(?:\?[a-zA-Z0-9_\-]+=[a-zA-Z0-9_\-]+)?)?(?:\&[a-zA-Z0-9_\-]+\=[a-zA-Z0-9_\-]+)*)$


Title: Update
Name: Ted Cambron
Date: 7/28/2007 12:36:21 AM
Comment:
Dang, a double post. :( After further test I made one more change and it's working quite well. Here's the finished product... ^(http\:\/\/[a-zA-Z0-9_\-]+(?:\.[a-zA-Z0-9_\-]+)*\.[a-zA-Z]{2,4}(?:\/[a-zA-Z0-9_]+)*(?:\/[a-zA-Z0-9_]+\.[a-zA-Z]{2,4}(?:\?[a-zA-Z0-9_]+\=[a-zA-Z0-9_]+)?)?(?:\&[a-zA-Z0-9_]+\=[a-zA-Z0-9_]+)*)$


Title: Update
Name: Ted Cambron
Date: 7/28/2007 12:34:11 AM
Comment:
Had to make a slight upate to the query part. ^(http\:\/\/[a-zA-Z0-9_\-]+(?:\.[a-zA-Z0-9_\-]+)*\.[a-zA-Z]{2,4}(?:\/[a-zA-Z0-9_]+)*(?:\/[a-zA-Z0-9_]+\.[a-zA-Z]{2,4}(?:\?[a-zA-Z0-9_]+\=[a-zA-Z0-9_]?)?)?(?:\&[a-zA-Z0-9_]+\=[a-zA-Z0-9_]+)*)$


Title: Update
Name: Ted Cambron
Date: 7/28/2007 12:25:29 AM
Comment:
Had to make a slight upate to the query part. ^(http\:\/\/[a-zA-Z0-9_\-]+(?:\.[a-zA-Z0-9_\-]+)*\.[a-zA-Z]{2,4}(?:\/[a-zA-Z0-9_]+)*(?:\/[a-zA-Z0-9_]+\.[a-zA-Z]{2,4}(?:\?[a-zA-Z0-9_]+\=[a-zA-Z0-9_]?)?)?(?:\&[a-zA-Z0-9_]+\=[a-zA-Z0-9_]+)*)$


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