[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

(DTPtechNote:1400) [ruby]1桁数字のみ全角に



#!usr/bin/ruby -Ks
=begin
・1桁数字のみを全角数字に
・URLやメールアドレス中の数字はすべて半角に
=end

require "jcode"

def zen2han(num)
	num.tr!("0-9", "0-9")
	return num
end
while line = ARGF.gets 
	line.tr!("0-9", "0-9")#数字はすべて全角に
	line.gsub!(/([0-9,\.]{2,})/) {zen2han($1)}
	line.gsub!(/([0-90-9a-zA-Z_\#!$%&`'*+\-{|}~^\/=?\.]+@[0-90-9a-zA-Z_\#!$%&`'*+\-{|}~^\/=?\.]+)/) {zen2han($1)}
	line.gsub!(/(https?:\/\/[\(\)%#!\/0-90-9a-zA-Z_$@.&+-,'"*=;?:~-]+)/) {zen2han($1)}
	print line
end