Java regex "[.]" vs "."

GDa*_*ger 8 java regex

I'm trying to use some regex in Java and I came across this when debugging my code.

What's the difference between [.] and .?

I was surprised that .at would match "cat" but [.]at wouldn't.

fal*_*tru 19

[.].从字面上匹配一个点(),同时.匹配除换行符(\n)之外的任何字符(除非你使用DOTALL模式).

您还可以使用\.("\\."如果您使用java字符串文字)字面匹配点.