Last active
August 29, 2015 14:21
-
-
Save craigsdennis/d9f6943c7cf5ab9fa8b6 to your computer and use it in GitHub Desktop.
Regular Expression example in Ruby
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
title = "Regular Expressions in 10 different languages" | |
# Nil if match not found | |
result = /.*\d+.*/.match(title) | |
# And extraction too | |
result = /(\d+)/.match(title) | |
if result | |
puts "There are %s languages represented" % result[1] | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment