Skip to content

Instantly share code, notes, and snippets.

@cheeaun
Created July 15, 2009 04:16
Show Gist options
  • Save cheeaun/147441 to your computer and use it in GitHub Desktop.
Save cheeaun/147441 to your computer and use it in GitHub Desktop.
/*
* Idea from http://james.padolsey.com/javascript/stringprototypeextract/
*/
String.implement({
extract: function(regex, n){
n = (n===undefined) ? 0 : n;
if (!regex.global) return this.match(regex)[n] || '';
var match, extracted = [];
while (match = regex.exec(this)) extracted.push(match[n] || '');
return extracted;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment