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/.