#! ruby -Ku require "kconv" def check(str) reg = /( ( \d #任意の数字 + #1回以上繰り返し ) ( yen #yenで終わる ) ) /x if reg =~ str then print(Kconv.tosjis("○") + str + "(" + $1 + ")\n") else print(Kconv.tosjis("×") + str + "\n") end end print(Kconv.tosjis("/((\d+)(yen))/x にマッチするかどうか\n\n")) check("Watch 3500yen") check("Apple 280yen") check("1350year")