From: Simon Strandgaard Date: 2004-05-15T00:47:55+09:00 Subject: Re: Regexp Error? Ara.T.Howard wrote: > On Fri, 14 May 2004, Simon Strandgaard wrote: > > On Fri, 14 May 2004 23:21:27 +0900 > > ts wrote: > > > >>>>> "S" == Simon Strandgaard writes: > > > > > > S> ts wrote: > > > S> [snip] > > > >> What do you expect with ? > > > >> > > > >> /(.*).*/ =~ "abc" > > > > > > S> According to the left-most-longest rule.. I would guess the output > > > S> should be ["abc", "abc"].. > > > > > > Then you have make .* match *twice* :-) > > > > > > If the regexp can't match the empty string in the second .* (because it's > > > included in the first), it must not give a result > > > > I don't understand you here.. (maybe your assumption is wrong) ? > > > 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. therefore we > all agree that > > '123-456'.gsub /.*$/, 'X' => 'XX' > > because if it __didn't__ '(.*).*' could not match 'abc' What Guy told me makes sense.. your explaination also makes sense. The output 'XX' is because GNU/Oniguruma uses the empty-string token. I guess sed and awk uses loop-detection instead, and therefore outputs 'X'. my engine uses loop-detection, it thus outputs more desired results. http://raa.ruby-lang.org/list.rhtml?name=regexp For instance my engine outputs /a(a|)*/ ~= 'aaab' -> ['aaa', 'a'] /a(|ab)*b/ ~= 'aaabbb' -> ['aabb', 'ab'] /x(y?)*z/ ~= 'xyz' -> ['xyz', 'y'] /x(y{0,2})*z/ ~= 'xyz' -> ['xyz', 'y'] If you try the same examples with Gnu or Oniguruma, you will see the last elements are empty, I guess this is because they use the empty-token concept. -- Simon Strandgaard