I am trying to implement a regular expression that basically will extract all elements within the ELEMENTS
row.
Say that I have this html string:
<tr> <td> ELEMENTS</td> <td> <element>A1</element> , <element>A2</element> </td></tr><tr> <td> MORE_ELEMENTS</td> <td><element> A3</element>, <element> A4</element>, <element> A5</element> </td></tr>
And I want to extract all elements within the ELEMENT
row (A1
, A2
and A3
) but not the elements within the MORE_ELEMENTS
row (A4
, A5
and A6
).
Using this regexp you can match all elements:
<element>([^<]+)<\/element>\s*,*\s*
But if I try to restrict to ELEMENT
S using this regexp:
<td>\s*ELEMENTS.*?<element>([^<]+)<\/element>\s*,*\s*
I match only the first element. I don't know how to match the ELEMENTS
row and then iterate
within it to extract all elements.
Tried this as well, but didn't work either:
<td>\s*ELEMENTS.*?<element>([^<]+)<\/element>\s*,*\s*(<element>([^<]+)<\/element>\s*,*\s*)*
Any ideas? Thanks very much in advance!
Migsy