Doug Mahugh retweeted Raymond Hettinger tweeting:
#python tip: Complicated regexes can be organized into readable, commented chucks.
https://docs.python.org/3/library/re.html#re.X
Twitter hasn’t gotten around to censoring Python related tweets for accuracy so I did check the reference:
re.X
re.VERBOSEThis flag allows you to write regular expressions that look nicer and are more readable by allowing you to visually separate logical sections of the pattern and add comments. Whitespace within the pattern is ignored, except when in a character class or when preceded by an unescaped backslash. When a line contains a # that is not in a character class and is not preceded by an unescaped backslash, all characters from the leftmost such # through the end of the line are ignored.
This means that the two following regular expression objects that match a decimal number are functionally equal:
…
Which is the better question?
Why would anyone want to produce a readable regex in Python?
or,
Why would anyone NOT produce a readable regex given the opportunity?
Enjoy!
PS: It occurs to me that with a search expression you could address such strings as subjects in a topic map. A more robust form of documentation than # syntax.