1
我刚刚在jruby上运行时发现。当文本中有中文/日文时,MatchData.begin()将始终返回0。MatchDB.begin(n)在jruby上始终返回0
# encoding: utf-8
text = 'i love dog @chichi dog dog'
text_cn = '我爱你狗狗 @chichi 狗狗'
text_jp = '私はあなたの犬を愛して @chichi ドッグ'
reg = /([@@])([a-zA-Z0-9_]{1,20})(.*)/o
puts "==== Text in English ===="
text.scan(reg) do |before, at, screen_name, list_slug|
puts $~.inspect
puts "1. #{$~.begin(1)}"
puts "2. #{$~.begin(2)}"
puts "3. #{$~.begin(3)}"
end
puts "==== Text in Chinese ===="
text_cn.scan(reg) do |before, at, screen_name, list_slug|
puts $~.inspect
puts "1. #{$~.begin(1)}"
puts "2. #{$~.begin(2)}"
puts "3. #{$~.begin(3)}"
end
puts "==== Text in Japanese ===="
text_jp.scan(reg) do |before, at, screen_name, list_slug|
puts $~.inspect
puts "1. #{$~.begin(1)}"
puts "2. #{$~.begin(2)}"
puts "3. #{$~.begin(3)}"
end
而且随着jruby-1.6.7.2
结果:
$ jruby -S test.rb
==== Text in English ====
#<MatchData "@chichi dog dog" 1:"@" 2:"chichi" 3:" dog dog">
1. 11
2. 12
3. 18
==== Text in Chinese ====
#<MatchData "@chichi 狗狗" 1:"@" 2:"chichi" 3:" 狗狗">
1. 0
2. 0
3. 0
==== Text in Japanese ====
#<MatchData "@chichi ドッグ" 1:"@" 2:"chichi" 3:" ドッグ">
1. 0
2. 0
3. 0
如果我ruby-1.9.2-p290
一切运行是正确的,我不知道是否有一些
我用下面的Ruby脚本测试我需要使用jruby来完成那些我错过的设置?
任何想法?