Skip to content

Instantly share code, notes, and snippets.

@tSU-RooT
Created December 9, 2014 15:03
Show Gist options
  • Save tSU-RooT/711a04d9d26364d5fd26 to your computer and use it in GitHub Desktop.
Save tSU-RooT/711a04d9d26364d5fd26 to your computer and use it in GitHub Desktop.
Check_Regexp
# coding: utf-8
print "check_regexp on Ruby\n"
print "正規表現の入力が終わったらSTARTと入力してください。\n"
print ">"
patterns = []
while str = STDIN.gets
str.chomp!
break if str == "START"
patterns.push(Regexp.new(str))
print ">"
end
print "Check Your Inputs!\n"
print "チェックが終了したらQUITと入力してください。\n"
print ">"
while str = STDIN.gets
str.chomp!
break if str == "QUIT"
for p in patterns
match_data = p.match(str, 0);
if match_data != nil
print "true\n"
if match_data.size > 1
for i in 1...match_data.size
print "#{i}:#{match_data[i]}\n"
end
end
else
print "false\n"
end
end
print ">"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment