PostgreSQL 正则表达式字边界? [英] PostgreSQL Regex Word Boundaries?

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

问题描述

PostgreSQL 是否支持 ?

Does PostgreSQL support ?

我正在尝试 AB 但它不匹配任何内容,而 (W|^)AB(W|$) 匹配.这两个表达本质上是一样的,不是吗?

I'm trying AB but it doesn't match anything, whereas (W|^)AB(W|$) does. These 2 expressions are essentially the same, aren't they?

推荐答案

PostgreSQL 使用 mMyY 作为单词边界:

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:

括号表达式有两种特殊情况:括号表达式[[:<:]][[:>:]]是约束条件,匹配分别在单词的开头和结尾的空字符串.单词被定义为一系列单词字符,前面和后面都不跟单词字符.单词字符是 alnum 字符(由 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 正则表达式字边界?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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