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)

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]* 

-chris



>> solution here is to use negated classes to make the match. Negated
>> Classes are not greedy they match untill an exception is made to the
>> class and thats it. thus:
>
>I think you're confused about what greedy means.
>
>Negated classes (assuming you mean "[^x]") are neither greedy nor 
>non-greedy.  The asterisk in "[^>]*" makes this greedy -- it will match 
>as many characters as it can.  ".*" is no more or less greedy -- it 
>matches as many characters as it can.  The difference is only in what is 
>a legal match.  "." matches any character (except nulls in 
>null-terminated strings), so it is more ... omnivorous?
>
>Example:
>"[^x]*a" (greedy) matching on "bad dog bad" will match "bad dog ba" 
>since it finds the longest possible match (until the last a or it finds 
>an x).
>"[^x]*?a" (non-greedy or lazy) matching on the same string gives "ba" 
>since it finds the shortest possible match.
>
>Does that make sense?
>
>--Ben

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Find out how CFTicket can increase your company's customer support 
efficiency by 100%
http://www.houseoffusion.com/banners/view.cfm?bannerid=49

Message: http://www.houseoffusion.com/lists.cfm/link=i:21:857
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

Reply via email to