On Mon, 3 Mar 2003 19:51:09 -0500, you wrote:

>preg_match_all('/begincommand(.*)endcommand/',$messagebody,$commandOuttake,P
>REG_PATTERN_ORDER);
[...]
> How
>do I change the criteria to stop at the first instance of a match?  How do I
>parse out only up to the first instance of "endcommand"?

Here's an excerpt from 'perldoc perlre':

By default, a quantified subpattern is "greedy", that is, it will
match as many times as possible (given a particular starting location)
while still allowing the rest of the pattern to match.  If you want it
to match the minimum number of times possible, follow the quantifier
with a "?".  Note that the meanings don't change, just the
"greediness".

As John Holmes has already pointed out, you can add the U modifier,
but I would recommend that you learn to use the ? quantifier, since
this is more portable as Perl doesn't recognize the U modifier.  So
you'd want to change this:

/begincommand(.*)endcommand/

to this:

/begincommand(.*?)endcommand/

If you have an install of Perl handy I also recommend taking a look at
'perldoc perlretut', I've found it very helpful.

HTH...

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to