是否必须在正则表达式的字符类(方括号)中对点进行转义? [英] Does a dot have to be escaped in a character class (square brackets) of a regular expression?
问题描述
正则表达式中的点.
与任何单个字符匹配.为了使正则表达式匹配点,必须对点进行转义:\.
A dot .
in a regular expression matches any single character. In order for regex to match a dot, the dot has to be escaped: \.
已向我指出在方括号[]
内的点不必转义.例如,表达式:
[.]{3}
将匹配...
字符串.
It has been pointed out to me that inside square brackets []
a dot does not have to be escaped. For example, the expression:
[.]{3}
would match ...
string.
不是吗,真的吗?如果是这样,那么所有正则表达式标准都适用吗?
Doesn't it, really? And if so, is it true for all regex standards?
推荐答案
在字符类(方括号)中,除^
,-
,]
或\
以外的任何字符都是文字.
In a character class (square brackets) any character except ^
, -
, ]
or \
is a literal.
此网站是出色的参考书,并且提供了许多有关不同正则表达式风味的细微差别的信息. http://www.regular-expressions.info/refcharclass.html
This website is a brilliant reference and has lots of info on the nuances of different regex flavours. http://www.regular-expressions.info/refcharclass.html
这篇关于是否必须在正则表达式的字符类(方括号)中对点进行转义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!