清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>
require 'strscan' lex = [/"[^\\"]*(?:\\.[^\\"]*)*"/m, # string /'[^\\']*(?:\\.[^\\']*)*'/m, # char /\/\*.*?\*\//m, # multi-line /\/\/(?:.*?\\(?:\r?\n|\r))*.*/, # single-line /.|\s+/] # rest ARGV.each do |source| stream = StringScanner.new File.read source until stream.eos? do code = stream.scan lex.find {|regex| stream.match? regex} print code unless code.start_with?('//') || code.start_with?('/*') end end