PostgreSQL Regex Word Boundaries?

前端 未结 3 1382
说谎
说谎 2020-11-28 06:09

Does PostgreSQL support \\b?

I\'m trying \\bAB\\b but it doesn\'t match anything, whereas (\\W|^)AB(\\W|$) does. These 2 expre

3条回答
  •  盖世英雄少女心
    2020-11-28 06:50

    A simple example

    select * from table_name where column ~* '\yAB\y';
    

    This will match AB ab ab - text text ab text AB text-ab-text text AB text ...

    But you have to use:

    select * from sometable where name ~* '\\yAB\\y';
    

    in case you have standard_conforming_strings flag set to OFF. Note the double slashes.
    You can set it manually :

    set standard_conforming_strings=on;
    

    Then :select * from table_name where column ~* '\yAB\y'; should work.

提交回复
热议问题