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

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find Pattern Title
Expression
(((file|gopher|news|nntp|telnet|http|ftp|https|ftps|sftp)://)|(www\.))+(([a-zA-Z0-9\._-]+\.[a-zA-Z]{2,6})|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(/[a-zA-Z0-9\&%_\./-~-]*)?
Description
You can use this regular expression in your PHP scripts to convert entered URL in text to URL link. Example: $text=ereg_replace("(((file|gopher|news|nntp|telnet|http|ftp|https|ftps|sftp)://)|(www\.))+(([a-zA-Z0-9\._-]+\.[a-zA-Z]{2,6})|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(/[a-zA-Z0-9\&%_\./-~-]*)?","<a href=\"./redir.php?url=\\0\" target=\"_blank\">\\0</a>",$text);
Matches
http://diskusneforum.sk | www.diskusneforum.sk | ftp://123.123.123.123/
Non-Matches
diskusneforum.sk
Author Rating: The rating for this expression. Martin Ille
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: almost perfect.
Name: Phil
Date: 8/4/2010 6:48:13 AM
Comment:
added rel="external" instead of target="_blank", needed a title attribute too, but found URLs perfectly so far!


Title: not work in FCK editor
Name: bharat
Date: 9/30/2009 2:33:52 AM
Comment:
http://i.telegraph.co.uk/telegraph/multimedia/archive/01004/adam_gilchrist_1004674c.jpg this url is not work in my FCK editor upload image system :(


Title: not work in FCK editor
Name: bharat
Date: 9/30/2009 2:32:43 AM
Comment:
http://i.telegraph.co.uk/telegraph/multimedia/archive/01004/adam_gilchrist_1004674c.jpg this url is not work in my FCK editor upload image system :(


Title: Entering invalid prefix with valid url still matches
Name: Frank
Date: 8/20/2009 11:09:27 AM
Comment:
Entering hxtxtxpx://www.blah.com will match because "www." fulfills the criteria. Pattern should read (also modified to include urls with querystrings and commas): ((^(file|gopher|news|nntp|telnet|http|ftp|https|ftps|sftp)://)|(^www\.))?(([a-zA-Z0-9\._-]+\.[a-zA-Z]{2,6})|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(/[a-zA-Z0-9\&\?%_\./-~-,])?


Title: ^^
Name: ^^;
Date: 3/2/2009 4:41:06 AM
Comment:
very good !!


Title: Error
Name: Vytenis
Date: 7/16/2007 10:26:29 AM
Comment:
Bad parsing the url: http://www.mrcbug.com/?id,6;v,15


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