Sorry if the question was duplicated
I have a XML file, something like
<item>
<attr1>attr1.1</attr1>
<attr2>attr1.2</attr2>
</item>
...
<item>
<attr1>attr2.1</attr1>
<attr2>attr2.2</attr2>
</item>
And all I want to do is use Regex to get an array of item. For some reason, I don’t want to use jQuery here(I have read about jQuery.parseXML).
Can you show me how to get all of the items, or something, function in javascript which like match_all() in PHP.
And here is my Regex,
/<item>([\w\W]+?)<\/item>/
Thank you!
As zerkms mentioned there are already ways of parsing XML in javascript that offer a greater range of robustness and flexibility. There is also one particularly infamous answer to the question of attempting to parse supersets of regular languages with regular expressions, in short, it’s not the best way to go about this.
However if you are interested in precisely this use case, there is unfortunately no functionality like match_all from php or findall in python’s re. Have a look at this stackoverflow, particularly the code block
In the first answer for some detail on finding many occurrences of the same regex in a similar fashion.