From: "Jesús Gabriel y Galán" Date: 2007-10-27T07:34:08+09:00 Subject: Re: Newlines included in bracket negation On 10/27/07, Phrogz wrote: > On Oct 26, 3:43 pm, "Jesús Gabriel y Galán" > wrote: > > > 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? > > The last four characters of the word "birthday" match the regexp / > h.*day/, without crossing any newlines. Perhaps you were thinking of / > h.+day/, which does not match. I need more sleep, for sure. I was of course thinking on the first "h" and the last "day". That explains it :-) irb(main):043:0> "happy\n\nday".match(re).captures NoMethodError: undefined method `captures' for nil:NilClass Thanks, Jesus.