且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为什么方括号内的点与任何字符都不匹配?

更新时间:2023-02-05 21:19:14

[。] 相当于逃避(点)字符,即 \\。

[.] 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.