Created
December 27, 2011 21:02
-
-
Save JoshCheek/1525097 to your computer and use it in GitHub Desktop.
Ruby 1.9 regex, named capture groups to local variables
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
/(?<area_code>\d{3}) (?<local_number>\d{3}-\d{4})/ =~ "123 456-7890" | |
local_variables # => [:area_code, :local_number] | |
area_code # => "123" | |
local_number # => "456-7890" | |
ENV['RUBY_VERSION'] # => "ruby-1.9.3-p0" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment