February 2012
Intermediate to advanced
1184 pages
37h 17m
English
If you were using a prehistoric version of Perl and you didn’t want greedy matching, you had to use a negated character class. (And, really, you were still getting greedy matching of a constrained variety.)
In modern versions of Perl, you can force nongreedy, minimal
matching by placing a question mark after any quantifier. Our same
username match would now be /.*?:/.
That .*? will now try to match as few
characters as possible, rather than as many as possible, so it stops at
the first colon rather than at the last.
Read now
Unlock full access