RE: [PHP] preg_match()
| From: | Jan Reiter | Date: | Wed, 09 Sep 2009 16:39:32 +0000 |
| Subject: | RE: [PHP] preg_match() | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-297832@lists.php.net to get a copy of this message | ||
Not quite, I'm sorry. As the outer expression prim_states( [...] ) captures,
the repetitive elements inside prim_state( [...] ) overwrite each other in
the matches array.
Of course I could get the first entry in matches, and search it again with
preg_match_all(), but that is what I'm trying to avoid. But maybe that's
what I have to after all if there is no other way.
Thanks & Regards,
Jan
-----Original Message-----
From: Ashley Sheridan [mailto:ash@ashleysheridan.co.uk]
Sent: Wednesday, September 09, 2009 6:21 PM
To: Jan Reiter
Cc: php-general@lists.php.net
Subject: Re: [PHP] preg_match()
On Wed, 2009-09-09 at 18:18 +0200, Jan Reiter wrote:
> Good Afternoon.
>
>
>
> This shouldn't be too complicated, but I can't come up with a solution for
> the problem right now. It's about RegEx in PHP (5.2)
>
>
>
> Is there a way to capture ALL sub elements of an expression like
> preg_match('@a(?[0-9])*b@' ,"a2345678b" , $matches); ??
>
> This would produce (below) whereas I'd like to get all the elements (2-8)
as
> an array entry each . ([1]=>2, [2]=>3 .)
>
>
>
> Result:
>
> array(2) {
>
> [0]=>
>
> array(1) {
>
> [0]=>
>
> string(9) "a2345678b"
>
> }
>
> [1]=>
>
> array(1) {
>
> [0]=>
>
> string(1) "8"
>
> }
>
> }
>
>
>
> preg_match_all doesn't do the trick.
>
>
>
> The Expression I want to use is
>
>
>
>
@prim_states[\s]*\((?<num>[0-9\s]*)(prim_state[\s]*\((?<flag>[a-fA-F0-9\s]*)
> tex_idxs[\s]*\(([0-9\s]*)\)([0-9\s]*)\)[\s]*)*\)@
>
>
>
> as I'm trying to parse a 3d Model File, that contains data in the form of
>
>
>
> prim_states ( 51
>
> prim_state ( 00000000 2
>
> tex_idxs ( 1 2 ) 0 3 0 0 1
>
> )
>
> prim_state ( 00000000 3
>
> tex_idxs ( 1 2 ) 0 0 1 0 1
>
> )
>
> prim_state ( 00000000 3
>
> tex_idxs ( 1 2 ) 0 4 1 0 1
>
> )
>
> [.]
>
> )
>
>
>
> Thank You!
>
>
>
> Regards,
>
> Jan
>
>
If your example is indicative of what you need, then couldn't you just
loop through all the elements inside of the match as it will be a
contiguous string of numbers.
Thanks,
Ash
http://www.ashleysheridan.co.uk
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Eingehende eMail ist virenfrei.
Von AVG überprüft - www.avg.de
Version: 8.5.409 / Virendatenbank: 270.13.71/2336 - Ausgabedatum: 09/08/09
20:45:00