Does PostgreSQL support \b
?
I'm trying \bAB\b
but it doesn't match anything, whereas (\W|^)AB(\W|$)
does. These 2 expressions are essentially the same, aren't they?
Does PostgreSQL support \b
?
I'm trying \bAB\b
but it doesn't match anything, whereas (\W|^)AB(\W|$)
does. These 2 expressions are essentially the same, aren't they?
PostgreSQL uses
\m
,\M
,\y
and\Y
as word boundaries:See Regular Expression Constraint Escapes in the manual.
There is also
[[:<:]]
and[[:>:]]
, which match the beginning and end of a word. From the manual:Exact word search in text:
I was facing following problem.
I wanted to search all contacts which has 'cto' as exact word in titles, but in results was getting results with title having 'director' in it, I was using following query
I also tried with whitspaces around wildcard as '% cto %', it was getting matched with text which contains ' cto ', got results like 'vp, cto and manger', but not results with exact title as 'cto'.
I wanted both 'vp, cto and manger' and 'cto' in results, but not 'director' in results
Following worked for me
A simple example
This will match
AB
ab
ab - text
text ab
text AB
text-ab-text
text AB text
...But you have to use:
in case you have
standard_conforming_strings
flag set toOFF
. Note the double slashes.You can set it manually :
Then :
select * from table_name where column ~* '\yAB\y';
should work.