I have a piece of code like this:
Foo.where("name ~* '.*#{string}.*'")
Where string has both word characters and non-word characters and if some of them are not escaped I get invalid Regular Expressions errors.
So I need to get postgreslq to take string as a literal or escape the meta-characters used by the regex. Is there a way to do it instead of getting a list of all meta-characters and adding the backslash?
I have looked at both these questions but none of the answers is exactly what I'm looking for:
Here the accepted answer escapes all non-word characters. And using that with my strings I am afraid there will be weird behaviors with escaped non-word characters.
Here the answer is specific to the question and can't be used in my case.