# Escaping from ilike

**URL:** <https://www.ruby-forum.com/t/escaping-from-ilike/119727>\
**Category:** Rails\
**Created:** [November 9, 2007, 5:35pm UTC](https://www.ruby-forum.com/t/escaping-from-ilike/119727 "2007-11-09T17:35:13Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/49beb7/32.png) [@jney](https://www.ruby-forum.com/u/jney)\
**Post date:** [November 9, 2007, 5:35pm UTC](https://www.ruby-forum.com/t/escaping-from-ilike/119727/1 "2007-11-09T17:35:13Z")

</div>

Hello,  
I’m try to escape text from ilike but it doesn’t work. when i type ‘%’  
it send the request ‘%%%’ so it return every record  
Here is the function.  
def self.autocomplete(text, options={})  
text = ‘%’ + self.sanitize\_sql(text.downcase.strip.squeeze(" ") )

- ‘%’  
self.find(:all, :conditions =\> [‘name ILIKE ?’,  
text]).collect(&:name)  
end

i even tried with gsub, something like gsub(/([%_])/, ‘\\1’) to  
escape ‘%’ and '_’ but i’m really familar to this function or regex.

any idea?  
regards.
