Skip to content

Instantly share code, notes, and snippets.

@JoshCheek
Created December 27, 2011 21:02
Show Gist options
  • Save JoshCheek/1525097 to your computer and use it in GitHub Desktop.
Save JoshCheek/1525097 to your computer and use it in GitHub Desktop.
Ruby 1.9 regex, named capture groups to local variables
/(?<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