Skip to content

Instantly share code, notes, and snippets.

@tototoshi
Created July 30, 2012 12:51
Show Gist options
  • Save tototoshi/3206691 to your computer and use it in GitHub Desktop.
Save tototoshi/3206691 to your computer and use it in GitHub Desktop.
named capturing in ruby's regexp
s = "abc:123"
p = /(?<alpha>[a-z]+):(?<num>\d+)/
m = p.match(s)
puts m[:alpha] #=> abc
puts m[:num] #=> 123
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment