Ruby 为什么 2 个 String 不一样?

sevk · February 14, 2014 · Last by sevk replied at February 14, 2014 · 2990 hits

class String
  def jhex
    self.split(/,|\s+/).map{|x| x.hex}.pack('c*')
  end
end
s  = "01 00 28 09 00 04 02 00 27 AA" .jhex
s1 = "01 00 05 09 00 04 02 00 0A AA" .jhex

s .force_encoding 'ascii-8bit'
s1.force_encoding 'ascii-8bit'

r = Regexp.new '[\001\002\003]\000(.*?)\xAA' , nil , 'n'

s .match(r)   #=> #<MatchData "\x01\x00(\t\x00\x04\x02\x00'\xAA" 1:"(\t\x00\x04\x02\x00'">
s1.match(r)   #=> nil  #这里竟然是 nil

1 Floor has deleted

#1 楼 @bhuztez r 没有状态。

s1 明显有个\n在里面你需要 m flag……

#3 楼 @Kabie 哦,多谢,我失误了。

You need to Sign in before reply, if you don't have an account, please Sign up first.