go to previous page   go to home page   go to next page

Answer:

.*[0-9]+.* -- matches

.*+[0-9]+.* -- fails

.*[0-9]++.* -- matches

.*[0-9]+.*+ -- matches

When to use Possessive Quantifiers

The main advantage of possessive quantifiers is speed. Since possessive quantifiers never give up what they have matched, no time is spent trying out alternatives. A regular expression that uses them will quickly succeed or quickly fail.

However, unless you are writting an application that does a great deal of pattern matching and that demands speed, possessive quantifiers are rarely useful.


QUESTION 23:

(Review: ) what is the default behavior of a quantifier? greedy, lazy, or possessive?