Skip to content

Instantly share code, notes, and snippets.

@mlomnicki
Created April 19, 2010 23:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mlomnicki/371808 to your computer and use it in GitHub Desktop.
Save mlomnicki/371808 to your computer and use it in GitHub Desktop.
regex as string index
s = 'michal@example.com'
s[/^([^@]+)@(.*)/, 1] # => michal
s[/^([^@]+)@(.*)/, 2] # => example.com
s.match(/^([^@]+)@(.*)/)[1] # => michal
s.match(/^([^@]+)@(.*)/)[2] # => example.com
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment