Postgresql - Functions and Operators 函数和运算 - Pattern Matching

LIKE:

'abc' LIKE 'abc' true 'abc' LIKE 'a%' true 'abc' LIKE '_b_' true 'abc' LIKE 'c' 不能匹配

SIMILAR TO:

'abc' SIMILAR TO 'abc' true 'abc' SIMILAR TO 'a' 不能匹配 'abc' SIMILAR TO '%(b|d)%' true 'abc' SIMILAR TO '(b|c)%' 不能匹配

POSIX Regular:

Operator

Description

Example

~

正则表达式匹配,大小写敏感

'thomas' ~ '.*thomas.*'

~*

正则表达式匹配,大小写不敏感

'thomas' ~* '.*Thomas.*'

!~

不匹配正则表达式,大小写敏感

'thomas' !~ '.*Thomas.*'

!~*

不匹配正则表达式,大小写不敏感

'thomas' !~* '.*vadim.*'

Quantifier

Matches

*

0个或多个

+

1个或更多

?

0个或1个

{m}

匹配正好是m个的

{m,}

m个或更多

{m,n}

m~n个

*?

非贪婪模式 *

+?

非贪婪模式 +

??

非贪婪模式 ?

{m}?

非贪婪模式 {m}

{m,}?

非贪婪模式 {m,}

{m,n}?

非贪婪模式  {m,n}

Constraint

Description

^

匹配开头

$

匹配结尾

(?=re)

正向肯定预查(look ahead positive assert),在任何匹配pattern的字符串开始处匹配查找字符串

(?!re)

正向否定预查(negative assert),在任何不匹配pattern的字符串开始处匹配查找字符串。

(?<=re)

反向(look behind)肯定预查,与正向肯定预查类似,只是方向相反。

(?<!re)

反向否定预查,与正向否定预查类似,只是方向相反。

Escape

Description

\a

alert (bell) character, as in C

\b

退格, as in C

\B

synonym for backslash (\) to help reduce the need for backslash doubling

\cX

(where X is any character) the character whose low-order 5 bits are the same as those of X, and whose other bits are all zero

\e

为ESC或失败的字符,八进制值为 033

\f

换页, as in C

\n

换行, as in C

\r

回车符, as in C

\t

tab符, as in C

\uwxyz

匹配 wxyz,wxyz是一个用4位十六进制数字表示的Unicode字符。

\Ustuvwxyz

匹配 stuvwxyz,stuvwxyz是一个用8位十六进制数字表示的Unicode字符。

\v

垂直制表符(tab), as in C

\xhhh

匹配 hhh,hhh是一个用8位十六进制数字表示的Unicode字符。

\0

匹配0,不是空值

\xy

匹配为0xy的八进制数值

\xyz

匹配为0xyz的八进制数值

Escape

Description

\d

匹配一个数字字符。等价于 [0-9]。

\s

匹配任何空白字符,包括空格、制表符、换页符等等。等价于 [ \f\n\r\t\v]。

\w

匹配非字母、数字、下划线。等价于 '[^A-Za-z0-9_]'。

\D

匹配一个非数字字符。等价于 [^0-9]。

\S

匹配任何非空白字符。等价于 [^ \f\n\r\t\v]。

\W

匹配非字母、数字、下划线。等价于 '[^A-Za-z0-9_]'。

Escape

Description

\A

只匹配字符串的开始字符

\m

仅在单词开头匹配

\M

仅在单词末尾匹配

\y

仅在单词的开头或结尾匹配。

\Y

仅在单词的开头或结尾处进行匹配。

\Z

只匹配字符串结束字符

Escape

Description

\m

反向引用第m个

\mnn

(where m is a nonzero digit, and nn is some more digits, and the decimal value mnn is not greater than the number of closing capturing parentheses seen so far) a back reference to the mnn'th subexpression

猜你喜欢

转载自blog.csdn.net/chuckchen1222/article/details/81386282
今日推荐