Skip to content

Instantly share code, notes, and snippets.

@onjin
Created March 28, 2014 11:24
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 onjin/9830568 to your computer and use it in GitHub Desktop.
Save onjin/9830568 to your computer and use it in GitHub Desktop.
import re
p = re.compile('^(?P<head>\d{2})(?:[-\s]?(?P<tail>\d{3})?$)')
zip = "-".join(p.match('11123').groups())
print zip
zip = "-".join(p.match('11-123').groups())
print zip
zip = "-".join(p.match('11 123').groups())
print zip
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment