标题总结得很好。我正在为 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/