By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,409 Members | 1,604 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,409 IT Pros & Developers. It's quick & easy.

quantifier minimizer

P: n/a
The ? symbol serves a number of purposes in PCRE. The quantifer
minimizer usage is the one I'm currious about. Specifically, the
output from a test script isn't what I'm expecting, and I'm wondering
why.

Here's the script:

<?
echo preg_replace('#.*?b#','','aabbc');
?>

Based on my understanding of the quantifer minimizer, the output should
be bc. However, running this results in c being outputted. As such, I
guess I'm just not understanding what ? as a quantifer minimizer is
supposed to do. Could someone explain it to me?

Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
yawnmoth wrote:
<?
echo preg_replace('#.*?b#','','aabbc');
?>

Based on my understanding of the quantifer minimizer, the output should
be bc. However, running this results in c being outputted.


Your understanding of <?> is probably spot on but you've just
overlooked the Kleene Star. There's in fact two replacements
here. The first is the one you expected, the replacement of
<aab> with the empty string. The second is the replacement of
<b> - the second <b>. The quantifier <*> means zero or more;
and so in the second replacement, <.*> matches nothing while
the <b> matches.

--
Jock
Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.