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

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find Pattern Title
Expression
^(http|https|ftp)\://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(:[a-zA-Z0-9]*)?/?([a-zA-Z0-9\-\._\?\,\'/\\\+&%\$#\=~])*[^\.\,\)\(\s]$
Description
This Regex (can be used e.g. in PHP with eregi) will match any valid URL. Unlike the other exapmles here, it will NOT match a valid URL ending with a dot or bracket. This is important if you use this regex to find and "activate" Links in an Text
Matches
https://www.restrictd.com/~myhome/
Non-Matches
http://www.krumedia.com. | (http://www.krumedia.com) | http://www.krumedia.com,
Author Rating: Not yet rated. Michael Krutwig
Source i found an URL regex here and refined it to exclude Dots and comas at the End
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: Why &?
Name: XML escaping
Date: 12/9/2014 9:52:17 AM
Comment:
What is & good for? This can only be useful when looking in HTML or XML, right?


Title: What about the top level domain 'name'?
Name: Sammy
Date: 7/25/2012 2:36:24 PM
Comment:
The top level domain 'name' has a length of four characters. Therefor I believe '{2,3}' should be replaced by '{2,4}'.


Title: FQDN
Name: sy
Date: 1/10/2010 12:23:48 PM
Comment:
A FQDN does in fact end with a dot.


Title: When the domain has (-) on it
Name: Carlos López
Date: 3/16/2009 12:03:28 PM
Comment:
I tried it on php but found a problem when there are dashes "-" on the domain name. Found the next workaround: from: [a-zA-Z0-9\-\.] to: [a-zA-Z0-9\.\-] Change the . and - order Thanks Michael, regards


Title: My changes
Name: Dirk Schoenfuss
Date: 8/16/2005 12:21:41 PM
Comment:
I have made some small alterations. I am now using the following code: function find_urls_in_text($string) { $URL="((http|https|ftp)\://)?[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(:[a-zA-Z0-9]*)?/?([a-zA-Z0-9\-\._\?\,\'/\\\+&%\$#\=~;])*"; $REGEX_LINK="[\s^(](".$URL."[^\.\,\)\(\s<])"; if ( preg_match_all("=$REGEX_LINK=", $string, $matches) ) return $matches[1]; else return false; }


Title: Works with IP addresses
Name: Robert Purcell
Date: 8/5/2005 1:06:55 AM
Comment:
^((http|https|ftp)\://)?[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(:[a-zA-Z0-9]*)?/?([a-zA-Z0-9\-\._\?\,\'/\\\+&%\$#\=~])*[^\.\,\)\(\s]$ This slight alteration makes it work with IP addresses. Also, I added that the http:// (or similar) part be optional because that's what my application needed.


Title: URLs with IP addresses?
Name: Jonathon
Date: 11/7/2004 5:03:41 AM
Comment:
What about URLs containing IP addresses, such as: http://127.0.0.1/blah/etc Other than this (major) deficit, this is a great expression.


Title: Re: My upgrade
Name: Ian Z
Date: 11/4/2004 5:15:22 PM
Comment:
That regex doesn't seem to work for me on the tester here. Gets no matches. What do the [[:<:]] and [[:>:]] do?


Title: My upgrade
Name: Gumidek
Date: 11/2/2004 9:45:53 AM
Comment:
[[:<:]]((http|https|ftp)\://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,10}(:[a-zA-Z0-9]*)?/?([a-zA-Z0-9\-\.\,_\?\'/\\\+&%\$#\=~;])*)[[:>:]] This expresion works much better


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