My users sometimes enter, instead of apostrophe ('
), symbols that look like apostrophe (‘
), which causes some problems with database.
I tried to replace them with gsub
like so:
result.gsub(/\‘/, "'")
result.gsub(/‘/, "'")
Neither of these options work - getting the error:
syntax error, unexpected $end, expecting ')'
return result.gsub(/\‘/, "'").gsub("’", "'")
^
Are they reserved by Ruby? How do I replace them?
If your text editor doesn't support UTF-8 characters like ‘
directly, you can escape them this way:
"\u2018"
So in your example, it would be:
result.gsub(/\u2018/, "'")
Try:
result.gsub("‘", "'")
It should work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With