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

查看:68
本文介绍了为什么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天全站免登陆