Matching Complete Words With RegEx

This is a useful tip for when you want to match a word to another word exactly. For example say I want to match the word ‘digit’ in a MySQL query. In a normal LIKE query the word ‘digitize’ would throw a match. We know these two words are NOT the same thing and therefore should not create a match. This is how we would create a query looking for an exact match of the word ‘digit’.

SELECT * FROM `mytable` WHERE `field` REGEXP '[[:<:]]myword[[:>:]]';