PostgreSQL Regex字边界? [英] PostgreSQL Regex Word Boundaries?

查看:93
本文介绍了PostgreSQL Regex字边界?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

PostgreSQL是否支持\b?

Does PostgreSQL support \b?

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

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使用\m\M\y\Y作为单词边界:

PostgreSQL uses \m, \M, \y and \Y as word boundaries:

\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 

请参见正则表达式约束逸出.

还有[[:<:]][[:>:]],它们匹配单词的开头和结尾.从手册:

There is also [[:<:]] and [[:>:]], which match the beginning and end of a word. From the manual:

括号表达式有两种特殊情况:括号表达式[[:<:]][[:>:]]是约束,分别在单词的开头和结尾匹配空字符串.单词被定义为单词字符序列,该单词字符既不位于单词字符之前也不位于其后.文字字符是数字字符(由ctype定义)或下划线.这是一个扩展,与POSIX 1003.2兼容,但未指定该扩展,在打算移植到其他系统的软件中应谨慎使用.通常最好使用下面描述的约束转义符(它们不再是标准的,但肯定更容易键入).

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).

这篇关于PostgreSQL Regex字边界?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆