Skip to content

Instantly share code, notes, and snippets.

@whylom
Created March 20, 2012 18:53
Show Gist options
  • Save whylom/2139733 to your computer and use it in GitHub Desktop.
Save whylom/2139733 to your computer and use it in GitHub Desktop.
Grep an array of words (with captures!)
words = ["Life", "Liberty", "and", "the", "pursuit", "of", "Happiness"]
words.grep(/^[A-Z]/)
#=> ["Life", "Liberty", "Happiness"]
words.grep(/^([A-Z])/) { $1 }
#=> ["L", "L", "H"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment