From: "Jesús Gabriel y Galán" Date: 2007-10-27T06:43:45+09:00 Subject: Re: Newlines included in bracket negation On 10/26/07, Chris Morris wrote: > Adding \n inside the brackets fixes it, I just wouldn't expect to have to do > this since I didn't add the multiline mode option. > > require 'test/unit' > > class TestRE < Test::Unit::TestCase > def test_newlines > src = "happy\n\nbirthday" > assert_equal("hday", src.scan(/h[^x\n]*?day/).to_s) > end > end There's also something I don't understand, similar to the above. I always thought that in a non-multiline regexp, the dot didn't match newlines (\n), so I don't understand this: irb(main):036:0> re = /(h)(.*)(day)/ => /(h)(.*)(day)/ irb(main):037:0> "happy\n\nbirthday".match(re).captures => ["h", "", "day"] irb(main):038:0> re = /(h)(.*)(day)/m => /(h)(.*)(day)/m irb(main):039:0> "happy\n\nbirthday".match(re).captures => ["h", "appy\n\nbirth", "day"] I thought the first case wouldn't match. Can anyone shed some light? Jesus.