1
=~/\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>'

为什么?

4

1 回答 1

1

它实际上有效:

1.9.3p385 :001 > "test test".match(/\p{L}/)
 => #<MatchData "t"> 
1.9.3p385 :002 > RUBY_VERSION
 => "1.9.3" 

你的问题应该是windows默认编码?区分大小写?疯狂?

"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>'
于 2013-05-23T00:45:50.450 回答