regex - How to make Python ignore indentation and \n in re expressions -


i need match large string this:

""" a=...b=...c=...d=... """ 

i used such re expression match string:

''' a=.+? [^abcd]+? c=.+? ''' 

as re expression long, split several lines according pep8. python matches implicit \n well, i.e. trying match:

a=(.+?)\\n[^abcd]+?\\nc=(.+?)\\n 

which not want. furthermore, cannot use pretty indentation because python matches white spaces well.

so how can out of this? want pretty indentation , right matching.

specify re.verbose (also known re.x) flag when creating regex:

pattern = re.compile(''' a=.+? [^abcd]+? c=.+? ''', re.verbose) 

from docs:

this flag allows write regular expressions nicer. whitespace within pattern ignored, except when in character class or preceded unescaped backslash, and, when line contains '#' neither in character class or preceded unescaped backslash, characters leftmost such '#' through end of line ignored.


Comments