Created
June 6, 2013 18:23
-
-
Save carlossanchezp/5723721 to your computer and use it in GitHub Desktop.
This file contains 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
# right expression, match | |
str = "12345" | |
eval = str.match /\A\d+\z/ | |
puts eval ? 'match' : 'no match' | |
# right expression, no match | |
str = "hello123world" | |
eval = str.match /\A\d+\z/ | |
puts eval ? 'match' : 'no match' | |
# equivalent? expression, match | |
str = "12345" | |
eval = str.match /^\d+$/ | |
puts eval ? 'match' : 'no match' | |
# equivalent? expression, no match | |
str = "hello123world" | |
eval = str.match /^\d+$/ | |
puts eval ? 'match' : 'no match' | |
# right expression, no match | |
str = " | |
12345 | |
" | |
eval = str.match /\A\d+\z/ | |
puts eval ? 'match' : 'no match' | |
# right expression, no match | |
str = " | |
hello | |
123 | |
world" | |
eval = str.match /\A\d+\z/ | |
puts eval ? 'match' : 'no match' | |
# wrong expression, match | |
str = " | |
12345 | |
" | |
eval = str.match /^\d+$/ | |
puts eval ? 'match' : 'no match' | |
# wrong expression, match | |
str = " | |
hello | |
123 | |
world" | |
eval = str.match /^\d+$/ | |
puts eval ? 'match' : 'no match' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment