Created
November 12, 2013 17:06
-
-
Save jstrimpel/7434663 to your computer and use it in GitHub Desktop.
I suck at regexes. I know there has to better regex for extracting all the values for a particular attribute from an of HTML string.
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
function getAttributeValues(html) { | |
var htmlSubstr = html, | |
match = true, | |
values = [], | |
start = 0; | |
while (match) { | |
htmlSubstr = htmlSubstr.substr(start); | |
match = htmlSubstr.match(/<[^>]*\s(?:some-attribute-name=["']([^"']*)["'])[^>]*>/); | |
if (match) { | |
values.push(match[1]); | |
start = match[0].length + match.index; | |
} | |
} | |
return values; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment