yegor256
yegor256

Reputation: 105133

why dot inside square brackets doesn't match any character?

Why this [.]+ Java regular expression doesn't match my "foo" text, while .+ matches perfectly (tested here)?

Upvotes: 16

Views: 3234

Answers (1)

Reimeus
Reimeus

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

Related Questions