views:

58

answers:

2

I have a database table with a column where every entry is a regular expression. For example, the rows in my table look like this:

table: email_address_templates email_address: /*.google.com/ email_address: /*.reddit.com/ email_address: /*.ac.uk/

I want to be able to search through this table, and find if a particular string matches one of the regular expressions.

In ruby, it would look like this:

EmailAddressTemplate.all.select do |ea|
  ea.match "[email protected]"
end

I am wondering if there is a way to do a similar thing in pure mysql.

A: 

MySQL can handle POSIX regular expressions.

However, these are pretty limited compared to Ruby's, so you will have to make sure everything is compatible.

Frank Krueger
+2  A: 
select email_address
from email_address_templates
where "[email protected]" RLIKE email_address_templates;
wallyk