Actions
Bug #18802
closedNegation of POSIX character class does not work
Description
https://docs.ruby-lang.org/ja/3.1/doc/spec=2fregexp.html#charclass_posix
また、[:^クラス名:]という記法でその否定を意味します。
For example, [:^ascii:]
is the negation of [:ascii:]
according to the document. But it does not work:
irb(main):001:0> RUBY_VERSION
=> "3.1.2"
irb(main):002:0> %w[あああ あ a b :].map { _1.match?(/[:^ascii:]/) }
=> [false, false, true, false, true] # matches a, c, i, s, : or ^
irb(main):003:0> %w[あああ あ a b :].map { _1.match?(/[^[:ascii:]]/) }
=> [true, true, false, false, false] # expected
Updated by mame (Yusuke Endoh) almost 3 years ago
- Status changed from Open to Rejected
Note that the sentence is written in the section of character class. So [:^ascii:]
must be used in a character class as follows:
irb(main):001:0> %w[あああ あ a b :].map { _1.match?(/[[:^ascii:]]/) }
=> [true, true, false, false, false]
If you want to improve the Japanese document, please contact on https://github.com/rurema/doctree/issues .
Updated by cohei (昂平 谷口) almost 3 years ago
Thank you! I misunderstood about character classes.
Actions
Like0
Like0Like0