Encode both: the string and the regexp (works for 98 out of 100 encodings including dummy ones)