From: Brian Candler Date: 2008-12-15T22:55:04+09:00 Subject: Re: ruby 1.9.1: Encoding trouble: broken US-ASCII String Ah, there is a preview here: http://books.google.co.uk/books?id=jcUbTcr5XWwC&pg=PA359&lpg=PA359&dq=ruby+internal+encoding&source=web&ots=fHCpudaxhB&sig=iJ8JSJsNQV_t1KhZhHQqgjBfTuU&hl=en&sa=X&oi=book_result&resnum=4&ct=result#PPA358,M1 Something like this may do the trick: text = File.open("..") do |f| f.set_encoding("ISO-8859-1") rescue nil f.read end But then you may as well just do: text.force_encoding("ISO-8859-1") rescue nil I'm not sure in which way the regexp is incompatible with the data read. I would have thought that a US-ASCII regexp should be able to match ISO-8859-1 data, and perhaps vice versa, but it seems not. I can't really replicate without a hexdump of your text.txt. But it would be interesting to see the result of: text.each_line do |line| p line.encoding p /foo/.encoding p line =~ /foo/ end Maybe what's really needed is a sort of "anti-/u" option which means "my regexp literals are meant to match byte-at-a-time, not character-at-a-time" Anyway, I'm afraid all this increases my inclination to stick with ruby 1.8.6 :-( -- Posted via http://www.ruby-forum.com/.