哪个正则表达式运算符表示“不"匹配此字符? [英] Which regular expression operator means 'Don't' match this character?

查看:46
本文介绍了哪个正则表达式运算符表示“不"匹配此字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

*, ?, + 字符均表示匹配该字符.哪个字符的意思是不"匹配这个?示例会有所帮助.

*, ?, + characters all mean match this character. Which character means 'don't' match this? Examples would help.

推荐答案

您可以使用否定字符类来排除某些字符:例如 [^abcde] 将匹配除 a,b,c 之外的任何内容,d,e 字符.

You can use negated character classes to exclude certain characters: for example [^abcde] will match anything but a,b,c,d,e characters.

您可以在字符类中使用速记,而不是字面上指定所有字符:[\w](小写)将匹配任何单词字符"(字母、数字和下划线),[\W](大写)将匹配除单词字符之外的任何内容;类似地,[\d] 将匹配 0-9 位数字,而 [\D] 匹配除 0-9 位数字以外的任何数字,依此类推.

Instead of specifying all the characters literally, you can use shorthands inside character classes: [\w] (lowercase) will match any "word character" (letter, numbers and underscore), [\W] (uppercase) will match anything but word characters; similarly, [\d] will match the 0-9 digits while [\D] matches anything but the 0-9 digits, and so on.

如果您使用 PHP,您可以查看 regex字符类文档.

If you use PHP you can take a look at the regex character classes documentation.

这篇关于哪个正则表达式运算符表示“不"匹配此字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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