Skip to content

Instantly share code, notes, and snippets.

@Ravenstine
Created August 26, 2016 22:56
Show Gist options
  • Save Ravenstine/23d655c84495387aeeea3233c01524fb to your computer and use it in GitHub Desktop.
Save Ravenstine/23d655c84495387aeeea3233c01524fb to your computer and use it in GitHub Desktop.
Did you know that you can name your match groups in a Regex?
"https://twitter.com/eh1030/status/12345/photo/1".match(/^(?<url>https?:\/\/twitter\.com\/[-a-zA-Z0-9+&@#%?=~_|!:,.;]+\/status(es){0,1}\/(?<tweetId>\d+)\/{0,1})/)
# => #<MatchData "https://twitter.com/eh1030/status/12345/" url:"https://twitter.com/eh1030/status/12345/" tweetId:"12345">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment