Skip to content

Instantly share code, notes, and snippets.

@SyunWatanabe
Created February 16, 2020 10:16
Show Gist options
  • Select an option

  • Save SyunWatanabe/80796b930ae2b1d89a1233554740cd68 to your computer and use it in GitHub Desktop.

Select an option

Save SyunWatanabe/80796b930ae2b1d89a1233554740cd68 to your computer and use it in GitHub Desktop.
# 例外処理 サンプルそのまま
print "Text?:"
text = gets.chomp
begin
print "Pattern?:"
pattern = gets.chomp
regexp = Regexp.new(pattern)
rescue RegexpError => e
puts "Invalid regexp #{e.message}"
retry
end
matches = text.scan(regexp)
if matches.size > 0
puts "Matched: #{matches.join(', ')}"
else
puts "Nothing matched"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment