gpt4 book ai didi

regex - PostgreSQL 正则表达式单词边界?

转载 作者:行者123 更新时间:2023-11-29 11:05:40 25 4
gpt4 key购买 nike

PostgreSQL 是否支持\b

我正在尝试 \bAB\b 但它不匹配任何内容,而 (\W|^)AB(\W|$) 匹配。这 2 个表达式本质上是相同的,不是吗?

最佳答案

PostgreSQL 使用 \m , \M , \y\Y作为单词边界:

\m   matches only at the beginning of a word
\M matches only at the end of a word
\y matches only at the beginning or end of a word
\Y matches only at a point that is not the beginning or end of a word

参见 Regular Expression Constraint Escapes在手册中。

还有[[:<:]][[:>:]] , 匹配单词的开头和结尾。来自 the manual :

There are two special cases of bracket expressions: the bracket expressions [[:<:]] and [[:>:]] are constraints, matching empty strings at the beginning and end of a word respectively. A word is defined as a sequence of word characters that is neither preceded nor followed by word characters. A word character is an alnum character (as defined by ctype) or an underscore. This is an extension, compatible with but not specified by POSIX 1003.2, and should be used with caution in software intended to be portable to other systems. The constraint escapes described below are usually preferable (they are no more standard, but are certainly easier to type).

关于regex - PostgreSQL 正则表达式单词边界?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3825676/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com