|
Posted by Jim Michaels on 02/12/06 10:14
"Nicholas Sherlock" <N.sherlock@gmail.com> wrote in message
news:ds0r17$kqt$1@lust.ihug.co.nz...
> David Wahler wrote:
>> Nicholas Sherlock wrote:
>>> /\[download:[^0-9]*([0-9]+)(,[0-9]+)*\]/i
>>>
>>> When I try it, it only returns the first and last items (Ie. "12",
>>> ",28"). What am I missing?
>>
>> (quote)
>> When a capturing subpattern is repeated, the value captured is the
>> substring that matched the final iteration. [...]
>> (end quote)
>>
>> So, it doesn't look like you can use regular expressions to split a
>> string like that. If you need to split based on a real regular
>> expression rather than a fixed string, check out pcre_split.
>
> Thanks, I didn't realize my pattern would be recursive/repetitive. As I
> don't really need to get each argument separately, I changed it to:
>
> /\[download:[^0-9]*([0-9]+(,[0-9]+)*)+\]/i
can shorten it here:
/\[download:[^\d]*([\d]+(,[\d]+)*)+\]/i
>
> Which returns for me the whole 1,2,3,4 block as a matched pattern, perfect
> :).
>
> Cheers,
> Nicholas Sherlock
[Back to original message]
|