Why is only ) a special character and not } or ]?

前端 未结 4 1150
没有蜡笔的小新
没有蜡笔的小新 2021-01-19 05:47

I\'m reading Jan Goyvaerts\' \"Regular Expressions: The Complete Tutorial and Reference\" to touch up on my Regex.

In the second chapter, Jan has a section on \"spec

4条回答
  •  天命终不由人
    2021-01-19 05:57

    From experiments, it appears that unlike ), the characters ] and } are only interpreted as delimiters when the corresponding opening [ or { has been met.


    Though IMO the same rule could apply to ), that's the way it is.

    This might be due to the way the parser was written: parenthesis can be nested so that the balancing needs to be checked, whereas brackets/curly braces are just flagged. (For instance, [[] is a valid class definition. [[]] is also a valid pattern but understood as [\[]\].)

提交回复
热议问题