|
Posted by gosha bine on 06/05/07 17:08
On 05.06.2007 17:18 ngmr80 wrote:
> Hi,
>
> I'm experiencing a problem when trying to capture substrings with
> preg_match_all() from strings like
>
> "set('Hello','World')"
>
> using the following Regular Expression (PERL syntax):
>
> "/^set\((?:'([^']+)'(?(?!\)),))+\)$/"
>
> The resulting matches array looks like this:
>
> Array
> (
> [0] => Array
> (
> [0] => set('Hello','World')
> )
>
> [1] => Array
> (
> [0] => World
> )
>
> )
>
> I wonder why "Hello" is not in the matches array. Did I do something
> wrong in my Regular Expression?
>
> Thanks in advance.
> Ingmar
>
Hi Ingmar
grouping is not automatic, to capture N strings you must have N groups
in your expression or use preg_match_all, for example:
$re1 = '/set\( (.*?) \)/x';
$re2 = "/' (?: \\\\. | [^'] )* ' /x";
preg_match($re1, "set('Hello','Wo\'rld')", $m);
preg_match_all($re2, $m[1], $m);
print_r($m);
--
gosha bine
extended php parser ~ http://code.google.com/p/pihipi
blok ~ http://www.tagarga.com/blok
Navigation:
[Reply to this message]
|