chris porter wrote:
> i wouldnt say confused.. i think the correct term should be "less
> greedy".. but in the eyes of someone learning.. its easier to
> describe '.*' (very greedy) as all consuming and uses lots of
> backtracking.. and [^x]* as stoping at X (minimal backtracking and
> fewer captured characters)
I completely disagree. There is a technical definition of greediness.
See below, or "Mastering Regular Expressions" from O'Reilly, or the Perl
documentation, etc.
> the illustration being:
>
> the quick brown fox jumped over the lazy bear
>
> (.*)b will match "the quick brown fox jumped over the lazy "
> and
> [^b]* will match "the quick "
>
> the term "greedy" really means "is this going to skip over occurances
> of the next statment simply because it can" and the answer is yes to
> .* and no to [^x]*
That actually isn't what "greedy" means. Greediness means that the
sub-expression will match the most characters possible while still
allowing the expression as a whole to match. Non-greedy or lazy
matching matches the fewest characters that will allow the expression as
a whole to match. Generally, the terms greedy and non-greedy or lazy
are only applied to the * and + operators, though I've seen it in
reference to the {n,m} and {n} constructs on occasion.
--Ben
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Discover CFTicket - The leading ColdFusion Help Desk and Trouble
Ticket application
http://www.houseoffusion.com/banners/view.cfm?bannerid=48
Message: http://www.houseoffusion.com/lists.cfm/link=i:21:859
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/21
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:21
Unsubscribe:
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.21
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54