=~/\p{L}/
当我在Rubular上测试时 - 它适用于选择版本1.9.2
但是irb:
>> RUBY_VERSION
=> "1.9.3"
?> "test test".match(/\p{L}/)
SyntaxError: (irb):3: invalid character property name {L}: /\p{L}/
from C:/Ruby193/bin/irb:12:in `<top (required)>'
from -e:1:in `load'
from -e:1:in `<main>'
为什么?
答案 0 :(得分:1)
它确实有效:
1.9.3p385 :001 > "test test".match(/\p{L}/)
=> #<MatchData "t">
1.9.3p385 :002 > RUBY_VERSION
=> "1.9.3"
您的问题应该是Windows默认编码?案例sensitivines? crazyness?
"test test".match(/\p{L}/u)
=> #<MatchData "t">
"test test".match(/\p{L}/n) # same error you got
SyntaxError: (irb):2: invalid character property name {L}: /\p{L}/
from /home/fotanus/.rvm/rubies/ruby-1.9.3-p385/bin/irb:16:in `<main>'