https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112021-06-29T09:28:54ZRuby Issue Tracking SystemRuby master - Bug #18013: Unexpected results when mxiing negated character classes and case-foldinghttps://bugs.ruby-lang.org/issues/18013?journal_id=926892021-06-29T09:28:54Zjirkamarsik (Jirka Marsik)
<ul></ul><p>This is a simpler reproducer.</p>
<pre><code>irb(main):003:0> /[^a]/i.match("a")
=> nil
irb(main):004:0> /[[^a]]/i.match("a")
=> #<MatchData "a">
</code></pre> Ruby master - Bug #18013: Unexpected results when mxiing negated character classes and case-foldinghttps://bugs.ruby-lang.org/issues/18013?journal_id=926912021-06-29T11:45:39Zduerst (Martin Dürst)duerst@it.aoyama.ac.jp
<ul></ul><p>Just a question: What's the purpose of nested character classes?</p>
<p>I didn't even know that there was such a thing as nested character classes.</p>
<p>Depending on the purpose of nested character classes, the right way to handle things may differ. This is just a wild guess, but if there's no difference between usual character classes and nested character classes, then there isn't really a purpose for nested character classes.</p> Ruby master - Bug #18013: Unexpected results when mxiing negated character classes and case-foldinghttps://bugs.ruby-lang.org/issues/18013?journal_id=926922021-06-29T12:05:15Zjirkamarsik (Jirka Marsik)
<ul></ul><p>duerst (Martin Dürst) wrote in <a href="#note-2">#note-2</a>:</p>
<blockquote>
<p>Just a question: What's the purpose of nested character classes?</p>
</blockquote>
<p>They are useful in combination with the set intersection operator <code>&&</code>. They let you, e.g., exclude characters from some character set, as in the example below, which considers all lowercase-letters except for the English vowels <code>aeiou</code>.</p>
<pre><code>irb(main):001:0> /[\p{Ll}&&[^aeiou]]/u.match("a")
=> nil
irb(main):002:0> /[\p{Ll}&&[^aeiou]]/u.match("b")
=> #<MatchData "b">
irb(main):003:0> /[\p{Ll}&&[^aeiou]]/u.match(".")
=> nil
irb(main):004:0> /[\p{Ll}&&[^aeiou]]/u.match("α")
=> #<MatchData "α">
</code></pre>