Reputation: 139
Before ruby 2.0, regex worked this way:
/\A[a-zа-я\d]+\z/i =~ 'привет' # => 0
/\A[a-z\p{Cyrillic}\d]+\z/i =~ 'привет' # => 0
I updated ruby 2.0, and it has a bug:
/\A[a-zа-я\d]+\z/i =~ 'привет' # => nil
/\A[a-z\p{Cyrillic}\d]+\z/i =~ 'привет' # => nil
How can I deal with this problem? Without \d
in the character class, it works correctly:
/\A[a-zа-я]+\z/i =~ 'привет' # => 0
Upvotes: 1
Views: 989
Reputation: 168101
This bug looks similar and may be related to this bug that I asked about before. I reported it to ruby trunk, and it has been accepted as a bug. Hopefully, it will be fixed.
Upvotes: 2
Reputation: 121000
The bug seems to be fixed in ruby-head
:
⮀ rvm use ruby-2.0.0-preview2
Using /home/am/.rvm/gems/ruby-2.0.0-preview2
⮀ irb
2.0.0dev :001 > regex = /\A[a-zа-я\d]+\z/i ; regex =~ 'привет'
# ⇒ nil
⮀ rvm use ruby-2.0.0-preview1
Using /home/am/.rvm/gems/ruby-2.0.0-preview1
⮀ irb
2.0.0dev :001 > regex = /\A[a-zа-я\d]+\z/i ; regex =~ 'привет'
# ⇒ nil
⮀ rvm use ruby-head
Using /home/am/.rvm/gems/ruby-head
⮀ irb
irb(main):001:0> regex = /\A[a-zа-я\d]+\z/i ; regex =~ 'привет'
# ⇒ 0
Upvotes: 1