So I receive some xml in plaintext (and no I can't use DOM or JSON because apparently I am not allowed to), I want to strip all elements encased in a certain element and put them into an array, where I can strip out the text in the individual segments. Now I am used to using POSIX regex and I will never actually understand the point behind PCRE regex, nor do I get the syntax.
Now here is the code I am using:
var strResponse = objResponse.text;
var strRegex = new RegExp("<item>(.*?)<\/item>","i");
var arrMatches = "";
var match;
while (match = strRegex.exec(strResponse)) {
arrMatches[] = match[1];
}
I have no idea why it won't find any matches with this code, can someone please help me on this and perhaps elaborate on what exactly it is I am continuously doing wrong with the PCRE syntax?
arrMatches[] = match[1];is invalid. You have to have something within the[]. It's not clear what you're using the brackets for, as you've assigned a string toarrMatches.arrMatches[] = match[1];is still incorrect. You need something inside the[]on the left. (I think you probably meant eitherarrMatches.push(match[1]);orarrMatches[arrMatches.length] = match[1];, both of which will addmatch[1]to the array.)