2

I have a regex:

/[!,.!:;\-\?\(\)"\s\n]/

Which works fine, but when I add:

«»

to the regex it causes an error:

invalid multibyte char (US-ASCII)

What is wrong? How do I fix that?

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Joe Half Face
  • 2,303
  • 1
  • 17
  • 45
  • Are you testing this in irb or within a ruby file? irb installations can have problems with unicode: http://stackoverflow.com/questions/4590725/how-can-i-input-multibyte-characters-in-rails-console-or-irb – pje Apr 16 '13 at 19:44
  • Try using the UTF-8 values: « = \xC2\xAB, » = \xC2\xBB – Otaia Apr 16 '13 at 19:57
  • pje, it's rails, server fails to start with this error – Joe Half Face Apr 16 '13 at 20:00

1 Answers1

2

On the first line of your file, write

#encoding: UTF-8

This is needed for ruby 1.9, but not for1.8 or 2.0

fotanus
  • 19,618
  • 13
  • 77
  • 111
  • @pguardiario Well, yeah. Otherwise you need to set the correct encoding. But IMHO, with few exceptions, if you aren't using UTF-8, you should – fotanus Apr 17 '13 at 11:52
  • That may be, but unless the document is encoded UTF-8, this will be a problem. – pguardiario Apr 17 '13 at 18:02