\S、\W、\D 在正则表达式中代表什么? [英] What do \S, \W, \D stand for in regex?
问题描述
在 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屋!