Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Ruby では、次の文字列から "a" で始まる単語の数を表示したい:an ant hello hint how are you
an ant hello hint how are you
スキャンで正規表現を使用できます
string.scan(/\ba/).size
p "an ant hello hint how are you".split.count{|word| word.start_with?('a')} #=> 3
"a asa a ss sa a a a ass a ".split.select {|w| w[0] == "a"}.size