From: Ammar Ali Date: 2010-11-24T01:12:47+09:00 Subject: Re: Regex negative look-behind bug? --0016e6d625f89e4bc70495baa452 Content-Type: text/plain; charset=UTF-8 On Tue, Nov 23, 2010 at 5:55 PM, Robert Klemme wrote: > On Tue, Nov 23, 2010 at 4:36 PM, Ammar Ali wrote: > > On Tue, Nov 23, 2010 at 4:36 PM, Ruby Nuby wrote: > > > >> irb, Ruby 1.9.1 > >> > >> What am I missing here? > >> > >> "b T T W b".match(/(? >> => nil > >> > >> #The second look-behind is now just a > >> "b T T W b".match(/(? >> => # > >> > >> #Regex stays the same, the T T are now in lower case > >> "b t t W b".match(/(? >> => nil > >> > >> #Look-behind only contains the t t condition now and, T T are back to > >> upper case > >> "b T T W b".match(/(? >> => nil > > > > No bug here. It is doing exactly what you asked: only match a w if it is > not > > preceded by 't t'. In all cases the w is preceded by 't t', and in the > case > > that did match (? as > > you asked, so it did match. > > That was an alternative! If the RX in the lookbehind can match, the > negative lookbehind must fail IMHO. > > The thing is what's in the lookbehind, and all assertions for that matter, is not really a regular expression. It is a fixed length literal. The only exception, AFAIK, is character sets because they are also fixed length. The engine needs to know how many characters to step back and examine. Also the first alternative that matches wins. Here it is in lower case and without ignoring case: >> "b t t w b".match( /(? nil There is a problem with the match though. I suspect there is an issue > with case sensitivity propagation > > irb(main):009:0> "b T T W b".match(/(? => # > irb(main):010:0> "b T T W b".match(/(?i: => nil > That's not a valid assertion any more, it is now an options specification. >> "b # > irb(main):013:0> RUBY_VERSION > => "1.9.1" > irb(main):014:0> RUBY_PATCHLEVEL > => 430 > I initially tried the cases with 1.9.2, but I tried the above with the latest 1.9.1 on my system (a bit older). >> RUBY_VERSION => "1.9.1" >> RUBY_PATCHLEVEL => 378 Regards, Ammar --0016e6d625f89e4bc70495baa452--