Other Resources:
Greediness of quantified subpatterns
What is the greediness of quantified subpatterns? What does it mean that a quantified subpattern is "greedy"?
How to show that a quantified subpattern is "greedy" on this PHP script: if ($t=10): echo "Just started...!"; endif; if ($t=11): echo "Hungry!"; endif; if ($t=12): echo ""Ah, lunch-time!"; endif;?
✍: FYIcenter.com
The greediness of quantified subpatterns is referring to the behavior on when to stop repeating a quantified subpattern in the matching process.
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.
For example: when applying pattern /a+a/ to "aaaa", the quantified subpattern /a+/ will, by default, match the first 3 characters "aaa" which still allowing the next subpattern /a/ to match the last character "a". In other words,
(a+)a # matches 'aaaa' with $1='aaa', not $1='a'
The regular expression to show the greediness of a quantified subpattern on the given PHP script:
(if .+ endif;)
if - matches 'if'
.+ endif; - matches as many characters as possible
while 'end if;' is at the end
2013-01-26, 0👍, 0💬
Popular Posts:
How to capture the Soso Spider entries from Web log file? Here are some Web log file entries: 127.0....
All credit card numbers issued by Diners Club must start with 300 through 305, 36 or 38 and have 14 ...
According to the IEEE 802 specification, a MAC address has 6 groups of 2 hexadecimal digits separate...
All credit card numbers issued by Diners Club must start with 300 through 305, 36 or 38 and have 14 ...
All credit card numbers issued by American Express must start with 34 or 37 and have 15 digits. For ...