Ensure regex and string have the same encoding.