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

后端 未结 1 1323
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-08 08:55

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

相关标签:
1条回答
  • 2021-02-08 09:57

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

    0 讨论(0)
提交回复
热议问题