Skip to content

Instantly share code, notes, and snippets.

@ndevenish
Created January 25, 2021 17:06
Show Gist options
  • Save ndevenish/ceaf235cc9c535843b2a42b048275a5a to your computer and use it in GitHub Desktop.
Save ndevenish/ceaf235cc9c535843b2a42b048275a5a to your computer and use it in GitHub Desktop.
regex for parsing python printf-style-formatting
re.compile("""
% # Percent
(?:\((?P<mapping>[^)]*)\))? # Mapping key
(?P<flag>[#0\-+ ])? # Conversion Flag
(?P<width>\*|\d+)? # Field width
(?P<precision>\.(?:\*?|\d*))? # Precision
[hlL]? # Unused length modifier
(?P<format>[diouxXeEfFgGcrsa%]) # Conversion type
""", re.VERBOSE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment