如何使用正则表达式来匹配没有任何字母,数字或特殊字符的单词?

时间:2022-08-19 09:38:01

I want to use regular expression to filter out pure Chinese name by this:

我想使用正则表达式来过滤掉纯中文名称:

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

But, according to this, it isn't possible,so I want to approach that from opposite direction,find content without any letter,digital and special character(I knew that it is not rigid),but can't find "and" operator,so how to do it?

但是,根据这个,它是不可能的,所以我想从相反的方向接近,找到没有任何字母,数字和特殊字符的内容(我知道它不是僵硬的),但找不到“和”运营商,那怎么办呢?

1 个解决方案

#1


2  

MariaDB uses PCRE regex library beginning with 10.0.5 version: "Starting with MariaDB 10.0.5, MariaDB switched to the PCRE regular expression library for enhanced regular expressions.".

MariaDB使用从10.0.5版开始的PCRE正则表达式库:“从MariaDB 10.0.5开始,MariaDB切换到PCRE正则表达式库以增强正则表达式。”

To match entries that contain Chinese letters use

匹配包含中文字母的条目使用

REGEXP '[\\x{4e00}-\\x{9fa5}]'

or even

REGEXP '\\p{Han}'

To match the reverse, entries with no Chinese letters, use:

要匹配反向,没有中文字母的条目,请使用:

REGEXP '^[^\\x{4e00}-\\x{9fa5}]*$'

or

REGEXP '^\\P{Han}*$'

#1


2  

MariaDB uses PCRE regex library beginning with 10.0.5 version: "Starting with MariaDB 10.0.5, MariaDB switched to the PCRE regular expression library for enhanced regular expressions.".

MariaDB使用从10.0.5版开始的PCRE正则表达式库:“从MariaDB 10.0.5开始,MariaDB切换到PCRE正则表达式库以增强正则表达式。”

To match entries that contain Chinese letters use

匹配包含中文字母的条目使用

REGEXP '[\\x{4e00}-\\x{9fa5}]'

or even

REGEXP '\\p{Han}'

To match the reverse, entries with no Chinese letters, use:

要匹配反向,没有中文字母的条目,请使用:

REGEXP '^[^\\x{4e00}-\\x{9fa5}]*$'

or

REGEXP '^\\P{Han}*$'