#! ruby -Ku require "kconv" def check(str) print(Kconv.tosjis(str + " は /abc/ に")) reg = Regexp.compile("abc") pos = (reg =~ str) if pos then print(Kconv.tosjis("マッチします\n")) print(Kconv.tosjis("位置は "), pos, Kconv.tosjis(" です\n")) else print(Kconv.tosjis("マッチしません\n")) end end check("abc") check("pabc") check("ppabc") check("ppabcppabc") check("pab")