From: dblack@... Date: 2007-07-25T05:15:08+09:00 Subject: Re: Regex Question Hi -- On Wed, 25 Jul 2007, seijin@gmail.com wrote: > Oh, I see. So using the "*" with just one ... errr... thing will > never match it? "banana" =~ /a*/ will always be 0 but "banana" =~ / > a*n/ will be 1 (one) ? It's just confusing because I think of > "greedy" as it trying to match as many characters as possible. So > that although "*" tell it to find 0 or more that it would work hard to > return the maximum number of matches. Keep in mind, though, that it's looking for a pattern-match starting at the left. If it finds it, it's finished; it's not going to keep scanning the string. In the leftmost position, it finds a match for a* -- namely, 0 occurrences of a. So it's done. Here's an example that might help clarify it: "xxyyxxxyyy" =~ /x*/ # 0 The longest stretch of x's is at position 5. However, the job of the match engine is not to find the maximum number of x's; it's to find the first match for /x*/, starting at the left. It finds that match at position 0. There are only two x's, but that's neither here nor there. David -- * Books: RAILS ROUTING (new! http://www.awprofessional.com/title/0321509242) RUBY FOR RAILS (http://www.manning.com/black) * Ruby/Rails training & consulting: Ruby Power and Light, LLC (http://www.rubypal.com)