Skip to content

Instantly share code, notes, and snippets.

@beepony
Created February 21, 2017 05:31
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 beepony/268001426e683170e68890cbc01b84ed to your computer and use it in GitHub Desktop.
Save beepony/268001426e683170e68890cbc01b84ed to your computer and use it in GitHub Desktop.
ruby regx
#!/usr/bin/env ruby
string = "RyanOnRails: This is a test"
one, two, three = string.match(/(^.*)(:)(.*)/i).captures
p one #=> "RyanOnRails"
p two #=> ":"
p three #=> " This is a test"
# better one
if match = string.match(/(^.*)(:)(.*)/i)
one, two, three = match.captures
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment