kd3zeg
Last Updated: September 09, 2019
·
2.099K
· nvie

Verbose regexes in Python

You can use verbose regexes in Python. Whitespace and comments will be stripped off by the compiler, so they're just as efficient, but more readable:

ignore_re = re.compile(r"""
  ^\..*/        # skip dotfiles
| docs/         # skip our docs
| /migrations/  # migrations
| ^[^/]+$       # a path without directories
""", re.VERBOSE)