regex - Postgresql 正则表达式匹配大写字母,支持 Unicode

标签 regex postgresql unicode

标题总结得很好。我正在为 Postgres ~ 运算符寻找匹配 Unicode 大写字符的正则表达式。 显而易见的方法行不通:

=> select 'A' ~ '[[:upper:]]';
 ?column? 
----------
 t
(1 row)

=> select 'Ó' ~ '[[:upper:]]';
 ?column? 
----------
 t
(1 row)

=> select 'Ą' ~ '[[:upper:]]';
 ?column? 
----------
 f
(1 row)

我使用的是 Postgresql 9.1,我的区域设置为 pl_PL.UTF-8。排序工作正常。

=> show LC_CTYPE;
  lc_ctype   
-------------
 pl_PL.UTF-8
(1 row)

最佳答案

PG 9.1 和旧版本的正则表达式引擎不能正确分类代码点不适合它一个字节的字符。 'Ó' 的代码点是 211 它是正确的,但是 'Ą' 的代码点是 260,超出了 255。

PG 9.2 在这方面做得更好,但仍然不是 100% 适合所有字母表。看这个commit在 PostgreSQL 源代码中,特别是评论的这些部分:

remove the hard-wired limitation to not consider wctype.h results for character codes above 255

Still, we can push it up to U+7FF (which I chose as the limit of 2-byte UTF8 characters), which will at least make Eastern Europeans happy pending a better solution

不幸的是,这没有被移植到 9.1

关于regex - Postgresql 正则表达式匹配大写字母,支持 Unicode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14277805/

相关文章:

java - 为 tomcat 重写 URL

postgresql - 安装新 Windows 后未创建 postgresql 用户

c# - nHibernate 二级缓存无法处理查询

Python utf-8,如何对齐打印出来

python - 循环打印 Unicode 元素

python - python 中 reg exps 的小问题

java - 从文件读取时省略所有空行

unicode - 垂直虚线ASCII或Unicode字符

正则表达式匹配没有标点符号的邮政编码

postgresql - 使用 PostGIS 快速查找附近用户