ruby on rails - How to properly escape a regular expression in Active Record where clause -


i using active record v4.2.1 query mysql database using regular expression. create following sql:

select `users`.* `users` (email regexp '[@\.]gmail\.com') 

however, cannot seem find correct way create sql using active record.


user.where("email regexp ?", "[@.]gmail.com").to_sql 

yields

"select `users`.* `users` (email regexp '[@.]gmail.com')" 

user.where("email regexp ?", "[@\.]gmail\.com").to_sql 

yields

"select `users`.* `users` (email regexp '[@.]gmail.com')" 

user.where("email regexp ?", "[@\\.]gmail\\.com").to_sql 

yields

"select `users`.* `users` (email regexp '[@\\\\.]gmail\\\\.com')" 

how active record escape sql?

the escaping looks wrong in console when using to_sql, last example sends mysql:

select `users`.* `users` (email regexp '[@\\.]gmail\\.com') 

you can confirm running actual query in console , checking log file.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -