|
Posted by d on 02/03/06 13:13
"Nicholas Sherlock" <N.sherlock@gmail.com> wrote in message
news:drvbnp$uhu$1@lust.ihug.co.nz...
> Hey there,
>
> I'm trying to get a Perl regular expression to work, and I can't seem to
> get it quite right.
>
> It should match text like [download: 12,20,28] and match the subpatterns
> "12", ",20", ",28".
>
> /\[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?
>
> Cheers,
> Nicholas Sherlock
Your pattern is trying to recursively match patterns, which is a grey area
according to the php manual at least. May I ask why you're using pattern
matching for this? You could just use:
$text="[download: 12,20,28]";
$id=explode(",", substr($text, 11, -1));
That would give you an array of 12, 20, 28, and without pattern matching...
dave
Navigation:
[Reply to this message]
|