#! ruby -Ku require "kconv" def check1(str) if /(?!0000)\d\d\d\d/ =~ str then print(Kconv.tosjis("○") + str + "(" + $& + ")\n") else print(Kconv.tosjis("×") + str + "\n") end end def check2(str) if /(?!0000)(?!9999)\d\d\d\d/ =~ str then print(Kconv.tosjis("○") + str + "(" + $& + ")\n") else print(Kconv.tosjis("×") + str + "\n") end end print(Kconv.tosjis("/(?!0000)\\d\\d\\d\\d/ にマッチするかどうか\n")) check1("1234") check1("9999") check1("0000") check1("802") print("\n") print(Kconv.tosjis("/(?!0000)(?!9999)\\d\\d\\d\\d/ にマッチするかどうか\n")) check2("1234") check2("9999") check2("0000") check2("802")