Return to Snippet

Revision: 40947
at February 25, 2011 02:04 by naren1012


Updated Code
<html>
<head>
<title>URL Matcher Regex</title>
<script>
 
function url_matcher($text)
{
//Original regex on http://daringfireball.net/2010/07/improved_regex_for_matching_urls
//(?i)\b((?:[a-z][\w-]+:(?:/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?������«������»���¢�¯�¿�½�¯�¿�½���¢�¯�¿�½�¯�¿�½���¢�¯�¿�½�¯�¿�½���¢�¯�¿�½�¯�¿�½]))

//Modified regex
text = text.replace(/\b((?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:(?:[^\s()<>.]+[.]?)+|\((?:[^\s()<>]+|(?:\([^\s()<>]+\)))*\))+(?:\((?:[^\s()<>]+|(?:\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»����]))/gi,
					"<a href='" + "$1" + "'>" + "$1" + "</a>");
return text;
}
 
function start()
{
 $text = "This regex is a modified version of the regex on http://daringfireball.net/2010/07/improved_regex_for_matching_urls <br/>";
 $text = $text + "This regex does not match the ellipsis as part of URL http://google.com...<== note that ellipsis not_part_of_link. <br/>"
$text = $text + "Does not match bit.ly/.jee but matches something.something/something.something bit.ly/j.e  <br/>"
 res = url_matcher($text);
 document.write('<b>Original Text :</b> <br/>');
 document.write($text);
 document.write('<br/><b>Clickified Text : </b><br/>');
 document.write(res);
}
 
</script>
</head>
 
<body onload='start()'>
 
</body>
</html>

Revision: 40946
at February 25, 2011 02:04 by naren1012


Updated Code
<html>
<head>
<title>URL Matcher Regex</title>
<script>
 
function url_matcher($text)
{
//Original regex on http://daringfireball.net/2010/07/improved_regex_for_matching_urls
//(?i)\b((?:[a-z][\w-]+:(?:/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?���«���»�¢ï¿½ï¿½�¢ï¿½ï¿½�¢ï¿½ï¿½�¢ï¿½ï¿½]))

//Modified regex
//(?i)\b((?:[a-z][\w-]+:(?:/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:([^\s()<>.]+[.]?)+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?���«���»�¢ï¿½ï¿½�¢ï¿½ï¿½�¢ï¿½ï¿½�¢ï¿½ï¿½]))

text = text.replace(/\b((?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:(?:[^\s()<>.]+[.]?)+|\((?:[^\s()<>]+|(?:\([^\s()<>]+\)))*\))+(?:\((?:[^\s()<>]+|(?:\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))/gi,
					"<a href='" + "$1" + "'>" + "$1" + "</a>");
return text;
}
 
function start()
{
 $text = "This regex is a modified version of the regex on http://daringfireball.net/2010/07/improved_regex_for_matching_urls <br/>";
 $text = $text + "This regex does not match the ellipsis as part of URL http://google.com...<== note that ellipsis not_part_of_link. <br/>"
$text = $text + "Does not match bit.ly/.jee but matches something.something/something.something bit.ly/j.e  <br/>"
 res = url_matcher($text);
 document.write('<b>Original Text :</b> <br/>');
 document.write($text);
 document.write('<br/><b>Clickified Text : </b><br/>');
 document.write(res);
}
 
</script>
</head>
 
<body onload='start()'>
 
</body>
</html>

Revision: 40945
at February 15, 2011 19:12 by naren1012


Updated Code
<html>
<head>
<title>URL Matcher Regex</title>
<script>
 
function url_matcher($text)
{
//Original regex on http://daringfireball.net/2010/07/improved_regex_for_matching_urls
//(?i)\b((?:[a-z][\w-]+:(?:/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?�«�»â��â��â��â��]))

//Modified regex
//(?i)\b((?:[a-z][\w-]+:(?:/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:([^\s()<>.]+[.]?)+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?�«�»â��â��â��â��]))

text = text.replace(/\b((?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:([^\s()<>.]+[.]?)+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))/gi,
					"<a href='" + "$1" + "'>" + "$1" + "</a>");
}
 
function start()
{
 $text = "This regex is a modified version of the regex on http://daringfireball.net/2010/07/improved_regex_for_matching_urls <br/>";
 $text = $text + "This regex does not match the ellipsis as part of URL http://google.com...<== note that ellipsis not_part_of_link. <br/>"
$text = $text + "Does not match bit.ly/.jee but matches something.something/something.something bit.ly/j.e  <br/>"
 res = url_matcher($text);
 document.write('<b>Original Text :</b> <br/>');
 document.write($text);
 document.write('<br/><b>Clickified Text : </b><br/>');
 document.write(res);
}
 
</script>
</head>
 
<body onload='start()'>
 
</body>
</html>

Revision: 40944
at February 10, 2011 20:17 by naren1012


Updated Code
<html>
<head>
<title>URL Matcher Regex</title>
<script>
 
function url_matcher($text)
{
//Original regex on http://daringfireball.net/2010/07/improved_regex_for_matching_urls
//(?i)\b((?:[a-z][\w-]+:(?:/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»����]))

//Modified regex
//(?i)\b((?:[a-z][\w-]+:(?:/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:([^\s()<>.]+[.]?)+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»����]))

 return $text.replace(/\b((?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:([^\s()<>.]+[.]?)+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»����]))/gi, "<a href='http://"+"$1"+"'>"+"$1"+"</a>");
}
 
function start()
{
 $text = "This regex is a modified version of the regex on http://daringfireball.net/2010/07/improved_regex_for_matching_urls <br/>";
 $text = $text + "This regex does not match the ellipsis as part of URL http://google.com...<== note that ellipsis not_part_of_link. <br/>"
$text = $text + "Does not match bit.ly/.jee but matches something.something/something.something bit.ly/j.e  <br/>"
 res = url_matcher($text);
 document.write('<b>Original Text :</b> <br/>');
 document.write($text);
 document.write('<br/><b>Clickified Text : </b><br/>');
 document.write(res);
}
 
</script>
</head>
 
<body onload='start()'>
 
</body>
</html>

Revision: 40943
at February 10, 2011 09:24 by naren1012


Updated Code
<html>
<head>
<title>URL Matcher Regex</title>
<script>
 
function url_matcher($text)
{
//Original regex on http://daringfireball.net/2010/07/improved_regex_for_matching_urls
//(?i)\b((?:[a-z][\w-]+:(?:/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))

//Modified regex
//(?i)\b((?:[a-z][\w-]+:(?:/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:([^\s()<>.]+[.]?)+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))

 return $text.replace(/\b((?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:([^\s()<>.]+[.]?)+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))/gi, "<a href='http://"+"$1"+"'>"+"$1"+"</a>");
}
 
function start()
{
 $text = "This regex is a modified version of the regex on http://daringfireball.net/2010/07/improved_regex_for_matching_urls <br/>";
 $text = $text + "This regex does not match the ellipsis as part of URL http://google.com...<== note that ellipsis not_part_of_link. <br/>"
 res = url_matcher($text);
 document.write('<b>Original Text :</b> <br/>');
 document.write($text);
 document.write('<br/><b>Clickified Text : </b><br/>');
 document.write(res);
}
 
</script>
</head>
 
<body onload='start()'>
 
</body>
</html>

Revision: 40942
at February 10, 2011 09:08 by naren1012


Updated Code
<html>
<head>
<title>URL Matcher Regex</title>
<script>
 
function url_matcher($text)
{
//Original regex on http://daringfireball.net/2010/07/improved_regex_for_matching_urls
//(?i)\b((?:[a-z][\w-]+:(?:/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))

//Modified regex
//(?i)\b((?:[a-z][\w-]+:(?:/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:([^\s()<>.]+[.]?[^\s()<>.]*)+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))

 return $text.replace(/\b((?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:([^\s()<>.]+[.]?[^\s()<>.]*)+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))/gi, "<a href='http://"+"$1"+"'>"+"$1"+"</a>");
}
 
function start()
{
 $text = "This regex is a modified version of the regex on http://daringfireball.net/2010/07/improved_regex_for_matching_urls <br/>";
 $text = $text + "This regex does not match the ellipsis as part of URL http://google.com...<== note that ellipsis not_part_of_link. <br/>"
 res = url_matcher($text);
 document.write('<b>Original Text :</b> <br/>');
 document.write($text);
 document.write('<br/><b>Clickified Text : </b><br/>');
 document.write(res);
}
 
</script>
</head>
 
<body onload='start()'>
 
</body>
</html>

Revision: 40941
at February 10, 2011 06:50 by naren1012


Initial Code
<html>
<head>
<title>URL Matcher Regex</title>
<script>
 
function url_matcher($text)
{
//Original regex on http://daringfireball.net/2010/07/improved_regex_for_matching_urls
//(?i)\b((?:[a-z][\w-]+:(?:/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))

//Modified regex
//(?i)\b((?:[a-z][\w-]+:(?:/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:([^\s()<>.]+[.]?[^\s()<>.]+)+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))

 return $text.replace(/\b((?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:([^\s()<>.]+[.]?[^\s()<>.]+)+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))/gi, "<a href='http://"+"$1"+"'>"+"$1"+"</a>");
}
 
function start()
{
 $text = "This regex is a modified version of the regex on http://daringfireball.net/2010/07/improved_regex_for_matching_urls <br/>";
 $text = $text + "This regex does not match the ellipsis as part of URL http://google.com...<== note that ellipsis not_part_of_link. <br/>"
 res = url_matcher($text);
 document.write('<b>Original Text :</b> <br/>');
 document.write($text);
 document.write('<br/><b>Clickified Text : </b><br/>');
 document.write(res);
}
 
</script>
</head>
 
<body onload='start()'>
 
</body>
</html>

Initial URL

                                

Initial Description
Modified regex of URL Matcher found on http://daringfireball.net/2010/07/improved_regex_for_matching_urls

Initial Title
Modified URL Matcher Regex

Initial Tags
regex, url, javascript

Initial Language
JavaScript