Skip to content

Instantly share code, notes, and snippets.

@adorr
Created February 3, 2012 22:37
Show Gist options
  • Save adorr/1733413 to your computer and use it in GitHub Desktop.
Save adorr/1733413 to your computer and use it in GitHub Desktop.
var target = target || "_blank";
var re = new RegExp("\\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`!()\[\]{};:\'\".,<>?]))","g");
text = "<a target=\"_blank\" href=\"http://www.google.com/\">http://www.google.com/</a>" +
" <a target=\"_blank\" href=\"http://www.desk.com/\">http://www.desk.com/</a>"
text = text.replace(re, function(str) {
var left = RegExp.leftContext;
// Chrome sometimes throws an exception when calling rightContext
// var right; try { right = RegExp.rightContext; } catch(e) { right = ""; };
var right = RegExp.rightContext || "";
if (is_auto_linked(left, right)) {
return str;
}
return "blah";
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment