Несколько групп захвата регулярных выражений using quantifiers

Is there a way to get multiple capture groups out of a regex that is using quantifiers? For example, say I have this data (simplified from what I have to deal with):

<td>Data 1</td>
<td>data 2</td>
<td>data 3</td>
<td>data 4</td>

Right now, if I write a regex like this:

(?:<td>(.+?)<\/td>\s*){4}

I end up with only one capture group, the last one "data 4". Is there a way to use the quantifier and end up with 4 capture groups, or am I forced to write the regex like this to get what I want:

<td>(.+?)<\/td>\s*<td>(.+?)<\/td>\s*<td>(.+?)<\/td>\s*<td>(.+?)<\/td>

Yes, I am well aware that I can hack this simple example up much easier programmatically and then apply and necessary regexes or simpler pattern matches. The data I am working with is far more complex and I would really like to use a regex to handle all of the parsing.

8
задан stema 16 May 2011 в 13:50
поделиться