UTF-8 regular expressions fail when working with non UTF-8 strings

Here are my changes:

1. Override the #encode method inside String class to fallback to using #force_encoding if it fails to find a converter.
2. If the argument string's UTF-8 encoding is invalid, then let's try encoding it again and remove all characters that we do not care about.