From: Ammar Ali Date: 2010-11-24T21:32:47+09:00 Subject: Re: Regex negative look-behind bug? --001636c5a8a4e15e9e0495cbad81 Content-Type: text/plain; charset=UTF-8 On Wed, Nov 24, 2010 at 12:57 PM, Robert Klemme wrote: > On Tue, Nov 23, 2010 at 5:12 PM, Ammar Ali wrote: > > > > 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. > > Docs say that the regexp cannot be unlimited. But it is by far not > only a fixed length literal. "|" is certainly meta in an assertion - > the second line would not match if the lookbehind assertion was a > literal. > Yes, please excuse the terseness of my last response. I wrote it as I was rushing out the door. What I meant, but did not properly clarify, is; the contents of assertions are not *full* expressions. They can not contain quantifiers, they can not contain captures, and they can not include backreferences or anything that can complicate determining the length of the contents. Obviously alternation is allowed, since that's what we were discussing. However, only as long as the alternatives abide by the limitations. Ruby's regular expression engine is quite flexible in this regard, as it allows the alternatives to be of different lengths, unlike some other engines that require them to be of the same length. ----8<---- > The root issue still exists > > irb(main):014:0> "a ac".scan /(? => [] > irb(main):015:0> "A Ac".scan /(? => ["c"] > irb(main):016:0> "ac".scan /(? => [] > irb(main):017:0> "Ac".scan /(? => [] > > ----8<---- > > IMHO this is a bug. OK, now that we've eliminated the syntax and the double-negative confusion, I see the issue clearly. Thank you for your patience :) It might be a bug, but since the contents of assertions do not go through the full eval/exec cycle of "regular" regular expressions, this could be just another limitation of assertions. It might be difficult to figure out the last options in effect because they can be inserted multiple times in an expression, on their own (from here on) and they can be nested. Which of these would be used? Maybe just use the top level options? That can potentially introduce more confusion. Anyway, it's definitely worth reporting. Worst case, we'll find out it's a limitation, and best case, it will end being a feature request, if not a bug. Is the OP able/willing to report this? http://redmine.ruby-lang.org/ Regards, Ammar --001636c5a8a4e15e9e0495cbad81--