Created
February 16, 2020 10:16
-
-
Save SyunWatanabe/80796b930ae2b1d89a1233554740cd68 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 例外処理 サンプルそのまま | |
| 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