From: Robert Klemme Date: 2004-06-30T15:37:52+09:00 Subject: Re: another strange regexp case "Kristof Bastiaensen" schrieb im Newsbeitrag news:pan.2004.06.29.18.06.03.518152@vleeuwen.org... > On Tue, 29 Jun 2004 11:05:43 -0600, Ara.T.Howard wrote: > > > >> irb(main):004:0> /(theone)?/.match(" theone").to_a > >> => ["", nil] > > > > ? means 'zero or one' > > > > we start a the beginning of ' theone' and instantly find a match: zero of > > them. > > > > > if you create a regexp without anchors and with portions that can match zero > > things and have not done so out of absolute need - your code has a bug. > > Thanks for the answer. I expected the pattern to expand greedily, > but I forgot it will return the first match, which is the empty > match. You are right, /(theone)?/ is a silly thing to write, > finally I just needed another regexp for my problem. This is a case of the simple general rule "Watch out for regular expressions that match the empty string". All sorts of problems can arise when using them and usually you don't want to match an empty string anyway. Kind regards robert