Posted on Thursday, January 29th (1101 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[[:>:]]'
