You are here: Re: Regex help « PHP Programming Language « IT news, forums, messages
Re: Regex help

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация