Created
December 28, 2014 21:49
-
-
Save eouw0o83hf/df1e6410e06b19d46e11 to your computer and use it in GitHub Desktop.
Javascript Simple Regex XML Parse
This file contains 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 tagRegExp(tag) { | |
return new RegExp("<" + tag + ">((.|[\r\n])*?)<\/" + tag + ">", "gmi") | |
} | |
function getElements(data, tag) { | |
var groups = data.match(tagRegExp(tag)); | |
var output = []; | |
for(var i = 0; i < groups.length; ++i) { | |
var matches = tagRegExp(tag).exec(groups[i]); | |
if(matches.length >= 2) { | |
output.push(matches[1]); | |
} | |
} | |
return output; | |
} | |
function getElement(data, tag) { | |
return getElements(data, tag)[0]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment