0

I have this method to make a search

def self.search(search)
  where("titulo LIKE ?", "([a-zA-Z0-9]*)[ X]*#{search}")
end

Right now doesn't recognize anything. I suspect it isn't recognizing the REGEX.

But i can't find any answers to how to use regex in the where clause

Does someone know?

1 Answer 1

2

Postgresql

The keyword for using regexp in Postgresql is SIMILAR TO.

def self.search(search)
  where("titulo SIMILAR TO ?", "([a-zA-Z0-9]*)[ X]*#{search}")
end

Mysql

If you're using Mysql then the keyword is REGEXP.

def self.search(search)
  where("titulo REGEXP ?", "([a-zA-Z0-9]*)[ X]*#{search}")
end

It would be nice to know what you're trying to do if you want better answers and maybe help with your regular expression. For instance, what are the results you're expecting, etc...

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.