在 ruby 的 api 中 Regexp 类提到"&&" ,它举了一个例子
/[a-w&&[^c-g]z]/ === /[abh-w]/
'^c-g'的意思我知道,但是后面的'z'是什么意思呢?(可能我之前说的不清楚,既然# ([a-w] AND ([^c-g] OR z)) 那么应该还能匹配'z',可是下面说和/[abh-w]/等价?这是为什么)
If the first character of a character class is a caret (^) the class is inverted: it matches any character except those named.
/[^a-eg-z]/.match('f') #=> #<MatchData "f">
A character class may contain another character class. By itself this isn’t useful because [a-z[0-9]] describes the same set as [a-z0-9]. However, character classes also support the && operator which performs set intersection on its arguments. The two can be combined as follows:
/[a-w&&[^c-g]z]/ # ([a-w] AND ([^c-g] OR z))
This is equivalent to: