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