Differences between `[.]` Vs `.` in regex

The following expressions do not match: /[.]*/ and /.*/ . Why is this and how do they differ from each other? What is the interaction between [] and special characters in regular expressions?

Thanks.

+4
source share
2 answers

The point . usually a wildcard matching any character. However, in the character class ( [] ), it is considered as a literal and corresponds only to a point.

+12
source
  • .* literally means "zero or more matches any character", where . acts as a wildcard.
  • [.]* literally means "combine zero or more dot characters . ", where . enclosed in the character class [] is mapped literally.
+8
source

All Articles