Created
July 15, 2009 04:16
-
-
Save cheeaun/147441 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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