Skip to content

Instantly share code, notes, and snippets.

@kindy61
Created November 10, 2009 17:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kindy61/231038 to your computer and use it in GitHub Desktop.
Save kindy61/231038 to your computer and use it in GitHub Desktop.
var o = "", bd = document.body, h = bd.innerHTML;
h += h;h += h;h += h;
console.time(1);
h.replace(
/(?:<img[^>]*?)(?:src *?= *?("[^"]+"|'[^']+'|[^ >]+))/ig,
function(m, src) {
src = src.replace(/^['"]/,'').replace(/['"]$/,'');
o += "<li>" + src + ' <img src="' + src + '" /></li>';
});
console.timeEnd(1);
console.time(4);
t=h.match(/(?:<img[^>]*?)(?:src *?= *?("[^"]+"|'[^']+'|[^ >]+))/ig)
console.timeEnd(4);
o = "";
console.time(2);
h.replace(
/(<img[^>]*)(src *= *("[^"]*"|'[^']*'|[^ >]*))/ig,
function(m, t, c, src) {
t = src; c = src.charAt(0);
if (c == '"' || c == "'") t = t.slice(1, -1);
o += "<li>" + t + " <img src=" + src + " /></li>";
});
console.timeEnd(2);
o = "";
console.time(3);
o = h.replace(
/^.*?(?:<img[^>]*?)(?:src *?= *?("[^"]+"|'[^']+'|[^ >]+))/img,
'<li>$1<img src="$1"/></li>');
console.timeEnd(3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment