I have an input that looks like this:
<ID>0<VAL>a1b<ID>1<VAL>a2b<ID>2<VAL>a3b<ID>3<VAL>a4b
I'd need to capture key-value pairs (e.g. id - val
) or at least an array of groups as the following:
[0, a1b, 1, a2b, 2, a3b, 3, a4b]
Capturing just one pair (i.e. when the input contains only a single pair) works with this:
(?>(?:<ID>(\d+))(?:<VAL>(.+)))?
the result being: [0, a1b]
.
But it doesn't work for multiple pairs - it captures 0 as a group then as a 2nd group it takes the rest of the input, excluding the first <VAL>
tag, as in: [0, a1b<ID>1<VAL>a2b<ID>2<VAL>a3b<ID>3<VAL>a4b]
Can someone point me to a direction I should look into?
UPDATE: what if <ID>
and <VAL>
are some special chars, for example 0x8F
and 0x9F
?