简体   繁体   English

双方括号[[]]在正则表达式中的含义是什么?

[英]What does double square brackets [[]] mean in a regex?

I ran into this RegExp /[[0]]/ in JavaScript, and have been wondering what it means. 我在JavaScript中遇到了这个RegExp /[[0]]/ ,并且一直在想它意味着什么。

I know that the outer pair of [] should be use as a character class, but what about the inner pair? 我知道外部的[]对应该用作一个字符类,但内部对呢? I searched in Google and found this link , but "Collating Sequences" doesn't seem to be it 'cuz I can't get /[[.some.]]/ work as this page claims. 我在谷歌搜索并找到了这个链接 ,但“整理序列”似乎并不是因为我无法得到/ /[[.some.]]/ 。]。

Thanks in advance if anyone can give me a hint. 如果有人能给我一个提示,请提前致谢。

/[[0]]/

is equivalent to: 相当于:

  • A [ or 0 character, followed by a ] character. 一个[0字符,后跟一个]字符。
    • Valid matches are: 有效匹配是:
      • []
      • 0]
    • Invalid matches: 匹配无效:
      • [0
    • Valid string, but probably not an expected match: 有效字符串,但可能不是预期的匹配:
      • [0] (matches 0] ) [0] (匹配0]

In other words: /(\\[|0)\\]/ or /[\\[0]\\]/ 换句话说: /(\\[|0)\\]//[\\[0]\\]/
In real words: ( [ or 0 ) plus ] . 用实话来说: ( [ or 0 ) plus ]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM