James Grey wrote a series of articles on working with Unicode, UTF-8 and Ruby 1.8.7 and 1.9.2. They're important reading.
With Ruby 1.8.7, we could add:
#!/usr/bin/ruby -kU
require 'jcode'
and get partial UTF-8 support.
With 1.9.2 you can use:
# encoding: UTF-8
as the second line of your source file and that will tell Ruby to default to UTF-8. Grey's recommendation is we do that with all source we write from now on.
That will not affect external encoding when reading/writing text, only the encoding of the source code.
Ruby 1.9.2 doesn't extend the usual \w
, \W
and \s
character classes to handle UTF-8 or Unicode. As the other comments and answers said, only the POSIX and Unicode character-sets in regex do that.