In IRB, I'm trying the following:
1.9.3p194 :001 > foo = "\xBF".encode("utf-8", :invalid => :replace, :undef => :replace) => "\xBF" 1.9.3p194 :002 > foo.match /foo/ ArgumentError: invalid byte sequence in UTF-8 from (irb):2:in `match'
Any ideas what's going wrong?
This is fixed if you read the source text file in using an explicit code page:
File.open( 'thefile.txt', 'r:iso8859-1' )