Skip to content

Instantly share code, notes, and snippets.

@MarcinMM
Created October 8, 2011 03:44
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save MarcinMM/1271824 to your computer and use it in GitHub Desktop.
Replace with callback to prettify URLs and image-ify images
var imageRegex = /\.(png|jpg|jpeg|gif)$/;
str= str.replace(/(\b(?:https?|ftp):\/\/[a-z0-9-+&@#\/%?=~_|!:,.;]*[a-z0-9-+&@#\/%=~_|])/gim,
function(str) {
if (str.match(imageRegex)) {
return('img src=' + str + 'end img src');
} else {
return('<b>[</b><a href="' + str + '" class="autolink" target="_blank">' + str.replace('http://','') + '</a><b>]</b>');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment