Reputation: 12873
Search the products with '^wall$', '\swall\s', '^wall ' or ' wall$' in its name. But it should not have results like 'wallpaper' or 'wonderwall'
SELECT *
FROM `products`
WHERE (products.name REGEXP 'wall?[:space]')
ORDER BY products.updated_at DESC
So far the above obviously
doesn't work. What should be the correct way to do this.
Updated the spec for clearer explanation.
Upvotes: 1
Views: 1291
Reputation: 22324
use TRIM(products.name) = 'wall' instead of a regex...
after question update, use mysql equivalent of \bwall\b
regex (word boundaries):
'[[:<:]]word[[:>:]]'
Upvotes: 2
Reputation: 2817
SELECT *
FROM `products`
WHERE (products.name REGEXP '[[:<:]]wall[[:>:]]')
ORDER BY products.updated_at DESC
Upvotes: 5