From: "Iñaki Baz Castillo" Date: 2009-01-29T08:57:54+09:00 Subject: Re: error with regular expression inside eval block El Jueves, 29 de Enero de 2009, Barun Singh escribió: > I'm seeing strange behavior with Ruby 1.8 when I try to evaluate a > regular expression inside an eval block. > > Consider the following: > > puts '1' =~ /^[\d]+$/ > > >> outputs "0" to the terminal > > eval %Q{'1' =~ /^[\d]+$/} > > >> outputs "nil" to the screen > > Could someone explain why the eval statement returns an incorrect result > for the regexp match? Thanks... It works if you escape the \ with \\ : eval %Q{'1' =~ /^[\\d]+$/} => 0 Not sure why the \ must be escaped into a block code. -- Iñaki Baz Castillo