Can someone supply me with the regexp for searching for a searchterm that is not preceded or followed by [a-z] and [A-Z], other characters are ok. -> i.e. when searching for 'key' i don't want keyboard in my searchresults but key. is okay.
Thanks!
Can someone supply me with the regexp for searching for a searchterm that is not preceded or followed by [a-z] and [A-Z], other characters are ok. -> i.e. when searching for 'key' i don't want keyboard in my searchresults but key. is okay.
Thanks!
If using Perl what you need is \b aka "word boundary" ...
m/\bkey\b/
Since you don't specify what regex engine you're using, I'll assume a baseline, in which case "[^A-Za-z]key[^A-Za-z]
" would be sufficient.
If you also want to catch the string at the start and end of the line, you'll also have to use "^key[^A-Aa-z]
" and "[^A-Aa-z]key$
".
As question is tagged with "mysql" I assume you are using mysql regexps. Then '[[:<:]]key[[:>:]]' is what you want. See the documentation at dev.mysql.com for details.