Regexp in MySQL
Posted on Thursday, January 29th (3217 days ago)
Sometimes I have to make mini search engines. Several engines later, I still never realized I could use regex in MySQL. Ok, this is more for me than you I suppose, but I found the information so interesting I had to save it here: The basic syntax to use regular expressions in a MySQL query is:
SELECT something FROM table WHERE column REGEXP 'regexp'
For example, to select all columns from the table events where the values in the column id end with 5587, use:
SELECT * FROM events WHERE id REGEXP '5587$'
A more elaborate example selects all columns of the table reviews where the values in the column description contain the word excellent:
SELECT * FROM reviews WHERE description REGEXP '[[:<:]]excellent[[:>:]]'
About Joseph R. B. Taylor
Joseph R. B. Taylor is a designer/developer who makes stuff for screens of all shapes and sizes. He currently works at Edvisors, Inc. where he creates screen-based experiences for used by millions of college students every year.