PDA

View Full Version : wildcard for ' ', '\n' or '$'


jcrypt
03-11-2010, 06:06 PM
Is there a wildcard that can be used in combination with LIKE that can be used for spaces, end of line characters or the end of a string?

table1
id(int) title(varchar) description(text)

SELECT * FROM table1 WHERE title LIKE 'example' OR description LIKE 'example'

If I use '%example%' then the results will include entries like 'examples' and 'example1'. I would like to only retrieve exact matches for the keyword where the keyword is separated by a space or the beginning or end of string. Is there a wildcard that I can use for this?

^example
' 'example
\nexample
example$
example' '
example\n

koko5
03-11-2010, 06:18 PM
Hi,

You have to use REGEXP (http://dev.mysql.com/doc/refman/5.1-maria/en/regexp.html)
Regards :)

jcrypt
03-11-2010, 06:25 PM
Ok, thanks for the tip. The following syntax seems to provide the behavior I was looking for.

SELECT * FROM table1 WHERE title REGEXP '[[:<:]]example[[:>:]]' OR description REGEXP '[[:<:]]example[[:>:]]'