在postgresql中使用正则表达式时需要使用关键字“~”,以表示该关键字之前的内容需匹配之后的正则表达式,若匹配规则不需要区分大小写,可以使用组合关键字“~*”;
相反,若需要查询不匹配这则表达式的记录,只需在该关键字前加否定关键字“!”即可。若正则表达式包含转义字符,则需在表达式前加关键字“E”。
| Operator | Description | Example |
|---|---|---|
~ |
Matches regular expression, case sensitive | 'thomas' ~ '.*thomas.*' |
~* |
Matches regular expression, case insensitive | 'thomas' ~* '.*Thomas.*' |
!~ |
Does not match regular expression, case sensitive | 'thomas' !~ '.*Thomas.*' |
!~* |
Does not match regular expression, case insensitive | 'thomas' !~* '.*vadim.*' |
例如:

本文介绍了在PostgreSQL中如何使用正则表达式进行匹配,包括使用`~`关键字,忽略大小写的组合,以及否定匹配的方法。同时提到了正则表达式的通用性和在ApsaraDB上的应用。
最低0.47元/天 解锁文章
1399

被折叠的 条评论
为什么被折叠?



