From: Brian Candler Date: 2010-09-08T19:36:11+09:00 Subject: Re: Regex breaks when string contains binary data Aisha Fenton wrote: > I can't see why the following Regex isn't working as expected. Maybe a > bug in ruby? > > puts "345HI".match(/HI|BYE/).inspect >> HI > puts "\345HI".match(/HI|BYE/).inspect >> nil Are you typing this in irb? Are you using any dodgy irb plugins like wirble or anything else in .irbrc? You should get a MatchData object as the response. For me it works exactly as expected: this is under Ubuntu Lucid with the stock 1.8.7 packages. $ irb --simple-prompt >> RUBY_VERSION => "1.8.7" >> RUBY_DESCRIPTION => "ruby 1.8.7 (2010-01-10 patchlevel 249) [x86_64-linux]" >> puts "345HI".match(/HI|BYE/).inspect # => nil >> puts "\345HI".match(/HI|BYE/).inspect # => nil >> puts "\345KI".match(/HI|BYE/).inspect nil => nil > I'm using Ruby 1.8.7 What exact version of ruby 1.8.7? (Show ruby -v). And where did you get it from? Did you compile it yourself from source, or did you install a ready-made binary package - if so, which one? What operating system are you running under? What results do you get if you try the following in irb? >> "\345HI".match(/HI|BYE/) => # >> "\345HI" =~ /HI|BYE/ => 1 >> "\345HI".bytes.to_a => [229, 72, 73] -- Posted via http://www.ruby-forum.com/.