Ruby Regex Error: incompatible encoding regexp match (ASCII-8BIT regexp with UTF-8 string) Ruby Regex Error: incompatible encoding regexp match (ASCII-8BIT regexp with UTF-8 string) ruby ruby

Ruby Regex Error: incompatible encoding regexp match (ASCII-8BIT regexp with UTF-8 string)


Your Regex is being "compiled" as ASCII-8BIT.

Just add the encoding declaration at the top of the file where the Regex is declared:

# encoding: utf-8

And you're done. Now, when Ruby is parsing your code, it will assume every literal you use (Regex, String, etc) is specified in UTF-8 encoding.

UPDATE: UTF-8 is now the default encoding for Ruby 2.0 and beyond.