regex - Whole word matching with dot characters in MySQL -
in mysql, when searching keyword in text field "whole word match" desired, 1 use regexp , [[:<:]] , [[:>:]] word-boundary markers:
select name tbl_name name regexp "[[:<:]]word[[:>:]]"
for example, when want find text fields containing "europe", using
select name tbl_name name regexp "[[:<:]]europe[[:>:]]"
would return "europe map", not "european union".
however, when target matching words contains "dot characters", "u.s.", how should submit proper query? tried following queries none of them correct.
1.
select name tbl_name name regexp "[[:<:]]u.s.[[:>:]]"
2.
select name tbl_name name regexp "[[:<:]]u[.]s[.][[:>:]]"
3.
select name tbl_name name regexp "[[:<:]]u\.s\.[[:>:]]"
when using double backslash escape special characters, suggested d'alar'cop, returns empty, though there "u.s. congress" in table
select name tbl_name name regexp "[[:<:]]u\\.s\\.[[:>:]]"
any suggestion appreciated!
this regex want:
select name tbl_name name regexp '([[:blank:][:punct:]]|^)u[.]s[.]([[:punct:][:blank:]]|$)'
this matches u.s.
when preceeded by:
- a blank (space, tab etc)
- punctuation (comma, bracket etc)
- nothing (ie @ start of line)
and followed by:
- a blank (space, tab etc)
- punctuation (comma, bracket etc)
- nothing (ie @ end of line)
see sqlfiddle edge cases covering above points.
Comments
Post a Comment