2012-04-03 140 views

回答

1

這裏是我的快速和骯髒的strings.rb:

#! /usr/bin/ruby 

ARGV.each do |filename| 
    File.open filename,"rb" do |f| 
     f.each_line do |line| 
      line.scan(/([\x32-\x7e]{4,})/).each {|a| puts a[0]} 
     end 
    end 
end 

這不是藝術或任何的工作 - 它只能在直US-ASCII。正則表達式的基本含義是「所有可打印的US-ASCII字符的大小爲4個字符或更多」。這實際上是strings(1)所做的。