为什么方括号内的点与任何字符都不匹配? [英] why dot inside square brackets doesn't match any character?
本文介绍了为什么方括号内的点与任何字符都不匹配?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么这个 [。] +
Java正则表达式与我的foo
文本不匹配,而。+
匹配完美(经过测试此处)?
Why this [.]+
Java regular expression doesn't match my "foo"
text, while .+
matches perfectly (tested here)?
推荐答案
[。]
相当于逃避。
(点)字符,即 \\。
。
[.]
is equivalent to escaping the .
(dot) character, i.e. \\.
.
一旦角色出现在角色类中,它失去了作为特殊角色的地位。
Once the character appears in a character class, it loses its status as a special character.
由于 foo
不包含任何点,所以没有任何匹配。另一方面,。+
是一个匹配所有内容的通配符贪婪表达式。
As foo
doesn't contain any dots, nothing is matched. .+
, on the other hand, is a wildcard greedy expression that matches everything.
这篇关于为什么方括号内的点与任何字符都不匹配?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文