[MacRuby] #1016: Regular expression 'negative look-ahead' not working properly

MacRuby ruby-noreply at macosforge.org
Wed Dec 1 06:37:30 PST 2010


#1016: Regular expression 'negative look-ahead' not working properly
----------------------------------+-----------------------------------------
 Reporter:  yasuimao@…            |       Owner:  lsansonetti@…        
     Type:  defect                |      Status:  new                  
 Priority:  blocker               |   Milestone:                       
Component:  MacRuby               |    Keywords:                       
----------------------------------+-----------------------------------------
 I'm not sure if I'm doing this properly, but let me try.

 It's hard to describe, but there seems to be a bug in regular expression
 negative look-ahead (?! ).  The regular expression below might not be
 optimal, but what it tries to do is a wild card text search for
 expressions with 0-2 words in between "it is" and "interesting" excluding
 "not".


 {{{
 text = "It is interesting. It is very interesting. It is very very
 interesting. It is not interesting. It is not very interesting."

 p text.scan(/it is(?:\ *(?!\bnot\b)\w+)?(?:\ *(?!\bnot\b)\w+)?
 interesting/i)
 }}}

 Results

 Ruby 1.8.7/RubyCocoa

 {{{
 => ["It is interesting", "It is very interesting", "It is very very
 interesting"]
 }}}

 MacRuby 0.7.1

 {{{
 => ["It is interesting", "It is very interesting"]
 }}}

 If I don't use negative look-ahead, both return the same array.

 {{{
 text = "It is interesting. It is very interesting. It is very very
 interesting. It is not interesting. It is not very interesting."

 p text.scan(/\bit is(?:\ *\w+)?(?:\ *\w+)? interesting\b/i)
 }}}

 Result - Ruby 1.8.7/RubyCocoa, MacRuby

 {{{
 => ["It is interesting", "It is very interesting", "It is very very
 interesting", "It is not interesting", "It is not very interesting"]
 }}}


 I also tried this at http://demo.icu-project.org/icu-bin/redemo and the
 result was the same as Ruby 1.8.7/RubyCocoa.

-- 
Ticket URL: <http://www.macruby.org/trac/ticket/1016>
MacRuby <http://macruby.org/>



More information about the macruby-tickets mailing list