![]() | Ned Batchelder : Blog | Code | Text | Site Verbose Python regular expressions » Home : Blog : April 2003 |
Verbose Python regular expressionsThursday 10 April 2003 Latest Python tidbit: the re module has an option to write regular expressions in re.VERBOSE format. This means that whitespace can be used to layout the regular expression in a more readable style, and comments can be included with hash marks. For example, this regular expression: logFmt = '\[[0-9]{8}T[0-9]{6}\.[0-9]{3}Z:[0-9](/[0-9]*)?\][ ]*.*' becomes: logFmt = ''' Admittedly, regular expressions are pretty dense no matter what you do, but at least this way you can try to pull them apart a little for future readers of the code (which includes yourself starting tomorrow). | |
Comments
Add a comment: