如何使用正则表达式匹配没有任何字母,数字或特殊字符的单词? [英] How to use regular expression to match word without any letter,digital or special character?

查看:584
本文介绍了如何使用正则表达式匹配没有任何字母,数字或特殊字符的单词?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

但是,根据,这是不可能的,因此,我想从相反的方向来处理,查找没有任何字母,数字和特殊字符的内容(我知道它并不严格),但是找不到和"运算符,那么该怎么做呢?

解决方案

MariaDB使用以10.0.5版本开头的 PCRE 正则表达式库:"

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

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

甚至

REGEXP '\\p{Han}'

要匹配反义词,不带中文字母的条目,请使用:

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

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

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?

解决方案

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.".

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}*$'

这篇关于如何使用正则表达式匹配没有任何字母,数字或特殊字符的单词?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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