Skip to content

Instantly share code, notes, and snippets.

@marcinbunsch
Created April 5, 2011 10:38
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 marcinbunsch/903408 to your computer and use it in GitHub Desktop.
Save marcinbunsch/903408 to your computer and use it in GitHub Desktop.
Simple regex to flip DD/MM/YY to MM/DD/YY and back
str = '4/11/01'
# => "4/11/01"
str.sub!(/(\d+)\/(\d+)\/(\d+)/, '\\2/\\1/\\3')
# => "11/4/01"
str.sub!(/(\d+)\/(\d+)\/(\d+)/, '\\2/\\1/\\3')
# => "4/11/01"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment