So… I’ve been working with WYSIWYG editors, and have realized, that they occasionally replace certain characters with the hex codes for that character, like the ' or the & for example.
How do I override String’s index method such that it includes these hex codes?
Like, when do somestring.index("\'hello there") how do I get it to search \' and '
note: single quote is escaped for clarity against double quotes.
what is the most efficient way to do this kind of string search?
is there something like this already built in.
Also, since I’m using external tools, I don’t really have a say in the format things are in.
THE SOLUTION:
ORIGINAL ANSWER:
String#indexdoesn’t just work for single characters, it can be used for a substring of any length, and you can give it a regular expression which would probably be best in this case:Another option would be to just decode the HTML entities before you start manipulating the string. There are various gems for this including html_helpers: