From: Florian Gross Date: 2004-06-30T02:27:54+09:00 Subject: Re: another strange regexp case Kristof Bastiaensen wrote: > Hi, Moin! > here is another regexp behaviour which surprises me. > There may be some logic behind it, but I fail to see it... > irb(main):004:0> /(theone)?/.match(" theone").to_a > => ["", nil] I think that this is about how greediness in Regexps works: A Regexp will try to match as much as possible starting at the current position, but even a "bad" match at the current position will be better than a "good" match at a later position in the String. Maybe it would be possible to do a version of .match that finds the "best" (== longest, if greedy) match in the whole string. I assume that it would be based on .scan in some kind of way. Regards, Florian Gross