I have an auto-generated file that is encoded in UTF-16LE and I want to write a Ruby script that searches for a version number via a regular expression and replaces it with a new version number. Here is what I initially was trying to use:
File.open(filepath,"rb:UTF-16") do |file|
file.each do |line|
line.gsub!(/FILEVERSION \d\.\d/,FILEVERSION)
end
end
This however did not work as I was getting an error message that said "incompatible encoding regexp match(US-ASCII regexp with UTF-16 string)". I tried to force encode my FILEVERSION string in UTF-16 but got the same error. One of my coworkers said that you can't effectively use regexes in UTF-16 encoding. Is there a workaround to this problem?