473,394 Members | 1,739 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

quantifier minimizer

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
1 2545
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Han | last post by:
The following pattern (which is one subpattern in a string of several) looks for the following $xxx,xxx.xx (with the dollar sign) or xxx,xxx.xx (space in replace of missing dollar sign) ...
3
by: Robert | last post by:
Hi, I'm interested in two applications for javascript. A profiler and a minimizer. I found several, but I am hoping to hear with which applications some of you guys have a good experience. I...
2
by: Laurent Bugnion [MVP] | last post by:
Hi group, A few years ago, I translated Douglas Crockford's JsMin from C to C#, because we wanted to use this functionality in our build process. JsMin is a code minimizer for JavaScript. It...
2
by: bhavanirayala | last post by:
Hi All, I am getting the following warning while running the perl script Warning is: Quantifier follows nothing before HERE mark in regex m/* << HERE /
6
by: =?ISO-8859-1?Q?Une_B=E9v?==?ISO-8859-1?Q?ue?= | last post by:
I wanted to test userAgent by a Regexp the goal : true if UA contains "AppleWebKit/528+ " or "AppleWebKit/525.12+ " note the final "+" false otherwise then i wrote :
12
by: Yashgt | last post by:
I have a large CSS file which has classes defined such as: myclass { margin-right:7px; margin-top:5px; padding-bottom:5px; padding-top:5px; } I would like to reduce the CSS file to its...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.