Skip to content

Instantly share code, notes, and snippets.

@carlossanchezp
Created June 6, 2013 18:23
Show Gist options
  • Save carlossanchezp/5723721 to your computer and use it in GitHub Desktop.
Save carlossanchezp/5723721 to your computer and use it in GitHub Desktop.
# 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