From: Kristof Bastiaensen Date: 2004-05-15T03:58:52+09:00 Subject: Re: Regexp Error? On Fri, 14 May 2004 10:41:20 -0600, Ara.T.Howard wrote: > On Fri, 14 May 2004, Kristof Bastiaensen wrote: > >> On Fri, 14 May 2004 08:54:22 -0600, Ara.T.Howard wrote: >> > >> > what guy is saying here is that __unless__ both '(.*)' __and__ '.*' >> > match in the above - you don't have match. we all agree that the >> > '(.*)' matches the entire 'abc' and we all agree that the pattern >> > '(.*).*' matches 'abc' - therefore we all agree that it's correct >> > that certain pattern match zero width positions in strings and >> > consume no chars whilst still matching. >> >> Agree until here. >> >> > therefore we >> > all agree that >> > >> > '123-456'.gsub /.*$/, 'X' => 'XX' >> > >> > because if it __didn't__ '(.*).*' could not match 'abc' >> > >> > >> > -a >> >> I don't agree. The things is, you can't really consume 'nothing'. If I >> follow your reasoning, the above should give 'XXX', because 123-456 >> matches /(.*)(.*)(.*)/. How much empty spaces are there between two >> characters? One, three, infinite? There have to be rules, and I would >> find the following the most logical one: >> >> * when the empty space is already matched before, don't match again, >> unless explicitly against ? or *. (gawk behaviour?) >> >> Kristof > > but then > > /^$/ would not match '' > > empty tokens must not consume and must stack > > -a I would say it does match, because the empty token wouldn't have been matched at that moment. Perhaps a better way to formulate it would be this: * consume the empty token when matching greedily, but still allow it to be matched against * and ?. This way the empty token will treated as part of any string (not a seperate entity). I don't want to say it is the only way, but it seems the most logical to me. (But maybe it is best to just avoid such a regexp :-) k