- The first Regular Expression Library on the Web!

Please support RegExLib Sponsors


Regular Expression Details

Title Test Find Pattern Title
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
Non-Matches | ( |,
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

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
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
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
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
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
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
^((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
What about URLs containing IP addresses, such as: 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
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
[[:<:]]((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-2018, | ASP.NET Tutorials