\S、\W、\D 在正则表达式中代表什么? [英] What do \S, \W, \D stand for in regex?

查看:53
本文介绍了\S、\W、\D 在正则表达式中代表什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 shell 脚本中,我们有 \t 代表制表符,\s 代表空格,\w 代表单词.\W(大写 W)和 \D(大写 D) 用于什么?

In shell scripting we have \t for tab , \s for whitespace , \w for word. What are \W (capital W) and \D (capital D) used for ?

推荐答案

\W\w 的对立面,\D\d 的反面.

\W is the opposite of \w and \D is the opposite of \d.

就像 \S\s 的对立面.

It's just like \S is the opposite of \s.

\W\D 分别将匹配 \w\d 分别不匹配的内容.

\W and \D respectively will match what \w and \d respectively don't match.

您可以查看本网站以获得更多解释.

You can have a look at this site for some more explanation.

\w 通常匹配 [A-Za-z0-9_](忽略外来字符)

\w typically matches [A-Za-z0-9_] (ignoring the foreign characters)

\W 因此匹配 [^A-Za-z0-9_]

从那以后

\d 通常匹配 [0-9](忽略外来数字)

\d typically matches [0-9] (ignoring the foreign digits)

\D 因此匹配 [^0-9]

这篇关于\S、\W、\D 在正则表达式中代表什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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