1

I want regular expression for exact word match for mysql select query. If i have below string from database

string :  my name is amit patel with surname amitnindroda

Now i want to match whole word amit from above string then it should find exact word amit and it should not find match from amitnindroda. Please suggest regular expression for mysql query

rock321987
  • 10,942
  • 1
  • 30
  • 43
shingala sohil
  • 153
  • 1
  • 12

1 Answers1

6

You can use REGEXP Keyword and the [[:<:]] and [[:>:]] word-boundary markers:

SELECT *
FROM tablename 
WHERE keywords REGEXP '[[:<:]]word[[:>:]]'

Example:

Input

id  name
1   my name is admin in userwindow
2   my name is user in adminWindow

Query:

SELECT * FROM test WHERE test.name REGEXP '[[:<:]]admin[[:>:]]'

Output:

 id  name
 1   my name is admin in userwindow

So You can see here above query is searching word 'admin' only.

Piyush Gupta
  • 2,181
  • 3
  • 13
  • 28