为什么 mariadb 正则表达式会给出相反的结果? [英] Why does mariadb regex give contrary result?

查看:18
本文介绍了为什么 mariadb 正则表达式会给出相反的结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一列包含以下内容:

I have a column that contains following content:

+------------+
| name       |
+------------+
| 你好世界    |
| HelloWorld |
| Hello世界  |
+------------+

我希望

SELECT `name` FROM `table`  WHERE `name` REGEXP '[u4e00-u9fa5]';

只给我这样的中文包含行:

gives me only Chinese contained row like this:

+------------+
| name       |
+------------+
| 你好世界    |
+------------+

但它实际上给了我相反的结果:

but it actually gives me contrary result:

+------------+
| name       |
+------------+
| HelloWorld |
| Hello世界  |
+------------+

我知道:

SELECT `name` FROM `table`  WHERE `name` NOT REGEXP '[u4e00-u9fa5]';

可以按预期工作,但我想知道为什么 mysql regexp 给出相反的结果?这是默认设置吗?还是我弄错了.提前谢谢.

can work as expected,but I want to know why mysql regexp gives contrary result?Is this the default setting?Or I made a mistake.Thanks in advance.

推荐答案

如果你正在检查一个 utf8 字符串是否包含 CJK 字符:

If you are checking to see if a utf8 string has CJK characters in it:

WHERE HEX(name) REGEXP '^(..)*E[456789]'

不包括不在BMP"平面的汉字.

That will not include the Chinese characters that are not in the "BMP" plane.

这篇关于为什么 mariadb 正则表达式会给出相反的结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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