Thanks Heesob Park ! That's exactly what I needed. Gaspard On Sun, May 18, 2008 at 9:59 AM, Heesob Park <phasis / gmail.com> wrote: > Hi, > > Gaspard Bucher wrote: >> I still cannot find a solution to disable regex warning in the >> following situation: >> >> def valid_regexp?(str) >> begin >> re = /#{str}/ >> true >> rescue >> false >> end >> end >> >> # should return false and not print a warning >> valid_regexp?("foo{bar}") >> => true, prints warning... >> > You can do something like this: > > def valid_regexp?(str) > begin > output = StringIO.open('','w') > $stderr = output > re = /#{str}/ > output.string !~ /warning:/ > rescue > false > ensure > $stderr = STDERR > end > end > > # should return false and not print a warning > valid_regexp?("foo{bar}") > > > Regards, > > Park Heesob > -- > Posted via http://www.ruby-forum.com/. > >