You can do recursive matching using the (?R) syntax in preg functions (Perl
Compatible Regular Expression).
----- Original Message -----
From: "Christopher William Wesley" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Cc: "Cameron Just" <[EMAIL PROTECTED]>
Sent: Tuesday, March 26, 2002 1:01 AM
Subject: Re: [PHP] Regular Expression Challenge
> You won't be able to do that with a regexp alone. Recursively matching
> isn't possible. You'll need a little help from some additional code.
>
> <?php
> $string = "wed-thurs 9:35, 14:56, 18:35"; // YOUR STRING
> $regexp = "^([a-z]+)-([a-z]+)[\ ]+(.*)$";
> // GETS (day)-(day) (any/all times)
> $find = ereg( $regexp, $string, $matches );
> $times = explode( ",", $matches[3] ); // BREAK APART (.*)
> print( $matches[1] . "<br>\n" . $matches[2] . "<br>\n" );
> while( list( $key, $val ) = each( $times ) ){
> print( trim( ${val} ) . "<br>\n" );
> }
> ?>
>
> That seems to do the trick. Hopefully that gets ya closer to where you
> want to go. If you really needed to regexp match on the times, you can
> do that within the while loop.
>
> g.luck,
> ~Chris /"\
> \ / Microsoft Security
Specialist:
> X The moron in Oxymoron.
> / \ http://www.thebackrow.net
>
> On Mon, 25 Mar 2002, Cameron Just wrote:
>
> > Hi,
> >
> > I am trying to pull out the following information via a regular
expression.
> >
> > The string I am searching on is 'wed-thurs 9:35, 14:56, 18:35'
> >
> > and I want it to retreive
> > wed
> > thurs
> > 9:35
> > 14:56
> > 18:35
> >
> > The regular expression I am using is
> > ([a-z]+)-([a-z]+) +([0-9]{1,2}:?[0-9]{0,2})[, ]*
> >
> > It seems to be grabbing the
> > wed
> > thurs
> > 9:35
> > but I can't seem to retrieve the rest of the times.
> >
> > Anyone have any ideas?
> >
> > BTW
> > There can be any number of 'times' in the string and also the 'times'
can
> > be with or without the colon and the minutes, hence the '}:?[0-9]{0,2}'
> > part of the regexp.
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php