How to search a word in exact match, for example how to search word ‘leak‘, but search results should not include words like ‘leaked‘ or ‘leaks‘ etc.
Help in both Javascript and MySQL would be appreciated.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Basically, you need to look for word boundaries. So don’t think of looking for the word
leak, but looking for the word$leak#, where$is an imaginary character that is at the beginning of every word and#is an imaginary character at the end of every word (Not a standard convention, just assume it for this example). The words are delimited, by, lets say whitespaces for now. So,leakedandleaksis$leaked#and$leaks#. As such, the only part that matches is$leakand not$leak#.To do that in MySQL, the condition would be:
Here,
[[:<:]]is the begin-word word-boundary and[[:>:]]is the end-word word-boundary.For JavaScript, the query would be:
Here, the sequence
\brepresents a word-boundary (in javascript, there is no distinction between begin-word and end-word boundaries). It won’t only work for whitespaces, but even punctuation characters, for example:will match
/\bleak\b/, butaleakwill not. (I am unsure about MySQL though)