The following expressions are not the same: /[.]*/
and /.*/
. Why is that, and how exactly are they different? What is the interaction between the []
and special characters in regular expressions?
Thank you.
The following expressions are not the same: /[.]*/
and /.*/
. Why is that, and how exactly are they different? What is the interaction between the []
and special characters in regular expressions?
Thank you.
Share Improve this question asked Oct 31, 2011 at 15:26 user961528user961528 1 |2 Answers
Reset to default 14The dot .
is normally a wildcard, matching any character. Within a character class (the []
) however, it is treated as a literal and only matches a dot.
.*
literally means "Match zero or more of any character", wherein the.
acts as a wildcard.[.]*
literally means "Match zero or more dot.
characters", wherein the.
enclosed in a character class[]
is matched literally.
/[.]*/
would be/\.*/
. – Matthew Crumley Commented Oct 31, 2011 at 16:49