From: xsdg Date: 2005-07-21T16:05:38+09:00 Subject: Multiline Regexp Bug I was working on untangling some data for someone in #ruby-lang, and I think I found a bug in the Regexp multiline support. irb(main):001:0> "a=12\nb=23\nc=34\nd=45\n".scan(/(?:[^=]+=.+)+/) => ["a=12\nb=23\nc=34\nd=45"] irb(main):002:0> "a=12\nb=23\nc=34\nd=45\n".scan(/(?: .+)+/x) => ["a=12", "b=23", "c=34", "d=45"] irb(main):003:0> "a=12\nb=23\nc=34\nd=45\n".scan(/(?:.+)+/) => ["a=12", "b=23", "c=34", "d=45"] irb(main):004:0> "a=12\nb=23\nc=34\nd=45\n".scan(/([^=]+=.+)+/) => [["\nd=45"]] irb(main):005:0> "a=12\nb=23\nc=34\nd=45\n".scan(/( .+)+/x) => [["a=12"], ["b=23"], ["c=34"], ["d=45"]] In the first line, which demonstrates the bug, the trailing .+ should not grab everything until the end of the string -- as the regexp is not in multiline mode, it should return exactly the same thing as lines 2 and 3. I included line 3 just to show that the //x option wasn't changing anything. Additionally, lines 4 and 5 show that the non-capturing nature of the parens in the first 3 lines is not to blame either. $ruby --version; irb --version ruby 1.8.2 (2005-01-10) [i386-linux] irb 0.9(02/07/03) $dpkg -l ruby1.8 irb1.8 libruby1.8 Desired=Unknown/Install/Remove/Purge/Hold | Status=Not/Installed/Config-files/Unpacked/Failed-config/Half-installed |/ Err?=(none)/Hold/Reinst-required/X=both-problems (Status,Err: uppercase=bad) ||/ Name Version Description +++-==============-==============-============================================ ii ruby1.8 1.8.2-2 Interpreter of object-oriented scripting lan ii irb1.8 1.8.2-2 Interactive Ruby (for Ruby 1.8) ii libruby1.8 1.8.2-2 Libraries necessary to run the Ruby 1.8 --xsdg