Last active
October 29, 2015 02:11
-
-
Save itosho/a52ea40df0200969883b to your computer and use it in GitHub Desktop.
Rubyでテンプレートファイルから日本語の文字列を抽出する ref: http://qiita.com/itosho/items/6472856c65b0725d48b2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 正規表現 | |
japanese_regex = /[\p{Han}\p{Hiragana}\p{Katakana},.、。ー・]+/ | |
File.open('./japanese.txt', 'w') do |japanese_file| | |
Dir.glob('views/**/*.html.erb') do |template_file| | |
# ファイル名出力 | |
japanese_file.puts("対象ファイル名:#{template_file}") | |
# ファイル読み込み | |
text = File.read(template_file, encoding: Encoding::UTF_8) | |
# 日本語抽出 | |
japanese_words = text.scan(japanese_regex) | |
uniq_japanese_words = japanese_words.uniq | |
# 日本語出力 | |
japanese_file.puts(uniq_japanese_words) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment