Reply to Re: RegExp help

Your name:

Reply:


Posted by Rik Wasmus on 11/08/07 20:33

On Thu, 08 Nov 2007 20:41:50 +0100, otrWalter@gmail.com =

<otrWalter@gmail.com> wrote:

> Note: $code is a single line of code that the previous segment of this=

> method has located.
>
> I have this...
>
> preg_match('/\bnew wBug\s*\(\s*(.+)\s*\);/i', $code, $arrMatches);
> $results =3D $arrMatches[1];
>
>
> it will find this...
>
> new wBug ( $myvar ); // <-- this is what $code contains
>
> and it will give me...
>
> $myvar
>
> Which is exactly what I want, for this instance, but if I have this...=

>
> new wBug ( $myvar, true ); // <-- this is what $code contains,
> this time
>
> I get this...
>
> $myvar, true
>
> I'd like to only get....
>
> $myvar
>
> Actually, I'd like to get each parameter in its own array element of
> '$arrMatches'
>
> My RegExp is limited on this one.

First of all, are you sure regex is the way to go here? It looks awfully=
=

like a parser should be involved...

And while it's perfectly doable to create a regex for it, why not apply =
=

KISS and:

if(preg_match('/\bnew wBug\s*\(\s*(.+)\s*\);/i', $code, $arrMatches)){
$results =3D $explode(',',arrMatches);
array_walk($results,'trim');
}
It's a LOT easier to maintain then a regex...
-- =

Rik Wasmus

[Back to original 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

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