最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Differences between`[.]` vs `.` in regex - Stack Overflow

programmeradmin12浏览0评论

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
  • 3 BTW, the "proper" way to escape special characters is with the backslash, so /[.]*/ would be /\.*/. – Matthew Crumley Commented Oct 31, 2011 at 16:49
Add a comment  | 

2 Answers 2

Reset to default 14

The 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.
发布评论

评论列表(0)

  1. 暂无评论