Reputation: 105133
Why this [.]+
Java regular expression doesn't match my "foo"
text, while .+
matches perfectly (tested here)?
Upvotes: 16
Views: 3234
Reputation: 159844
[.]
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.
As foo
doesn't contain any dots, nothing is matched. .+
, on the other hand, is a wildcard greedy expression that matches everything.
Upvotes: 32