Reputation: 1459
On page 107 of the book Programming PHP by Kevin Tatroe and Peter MacIntyre, 3rd edition, it is stated that in PHP regular expressions, there is a nongreedy version {m}?
of the quantifier {m}
. The latter quantifier means "exactly m times" and I am wondering how this can be greedy or nongreedy?
Upvotes: 3
Views: 54
Reputation: 627101
A limiting quantifier can be both greedy and lazy (reluctant). The difference is only visible when you use both minimum and maximum values, e.g. {1,5}
and {1,5}?
.
When you use just the minimum threshold value, greedy and lazy versions yield the same behavior.
It seems that the {m}?
is just there to keep consistency ({n}
and {n,m}
are both forms of the same limiting quantifier that can be lazy or greedy), but is really redundant.
Upvotes: 2