简体   繁体   中英

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

I ran into this RegExp /[[0]]/ in JavaScript, and have been wondering what it means.

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.

Thanks in advance if anyone can give me a hint.

/[[0]]/

is equivalent to:

  • A [ or 0 character, followed by a ] character.
    • Valid matches are:
      • []
      • 0]
    • Invalid matches:
      • [0
    • Valid string, but probably not an expected match:
      • [0] (matches 0] )

In other words: /(\\[|0)\\]/ or /[\\[0]\\]/
In real words: ( [ or 0 ) plus ] .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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