On 15/04/2015 00:49, Alan Gauld wrote:
On 14/04/15 13:21, Steven D'Aprano wrote:

although I would probably want to write it out in verbose mode just in
case the requirements did change:


r"""(?x)    (?# verbose mode)
     (.+?):  (?# capture one or more character, followed by a colon)
     \s+     (?# one or more whitespace)
     (\d+)   (?# capture one or more digits)
     (?:     (?# don't capture ... )
       \s+       (?# one or more whitespace)
       \(.*?\)   (?# anything inside round brackets)
       )?        (?# ... and optional)
     \s*     (?# ignore trailing spaces)
     """

That's a hint to people learning regular expressions: start in verbose
mode, then "de-verbose" it if you must.

New one on me. Where does one find out about verbose mode?
I don't see it in the re docs?

I see an re.X flag but while it seems to be similar in purpose
yet it is different to your style above (no parens for example)?


https://docs.python.org/3/library/re.html#module-contents re.X and re.VERBOSE are together.

--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to