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

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

问题描述

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

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

但是,根据this,这是不可能的,所以我想从相反的方向接近,找到没有任何字母,数字和特殊字符的内容(我知道它不死板),但是找不到和"运算符,那怎么办?

解决方案

MariaDB 从 10.0.5 版本开始使用 PCRE 正则表达式库:从 MariaDB 10.0.5 开始,MariaDB 切换到 PCRE 正则表达式库以增强正则表达式.".p>

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

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

甚至

正则表达式 '\p{Han}'

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

正则表达式 '^[^\x{4e00}-\x{9fa5}]*$'

正则表达式 '^\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天全站免登陆