正则表达式:如何在没有下划线的情况下表达\ w [英] Regular Expressions: How to Express \w Without Underscore

查看:269
本文介绍了正则表达式:如何在没有下划线的情况下表达\ w的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一种简洁的表达方式:

Is there a concise way to express:

\w but without _

也就是说,"\ w中包含的所有字符,但_除外"

That is, "all characters included in \w, except _"

之所以这样问,是因为我正在寻找最简洁的方式来表示域名验证.域名可以包含小写和大写字母,数字,句号和破折号,但不能包含下划线. \ w包括以上所有内容以及下划线.那么,有没有办法通过正则表达式语法从\ w中删除"下划线?

I'm asking this because I'm looking for the most concise way to express domain name validation. A domain name may include lowercase and uppercase letters, numbers, period signs and dashes, but no underscores. \w includes all of the above, plus an underscore. So, is there any way to "remove" an underscore from \w via regex syntax?

已编辑:我要问的是PHP中使用的正则表达式.

Edited: I'm asking about regex as used in PHP.

提前谢谢!

推荐答案

以下字符类(在Perl中)

the following character class (in Perl)

[^\W_]

\W[^\w]

这篇关于正则表达式:如何在没有下划线的情况下表达\ w的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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