p = """
    (?<TAG> \\b(?:NOTE|LEGACY|HACK|TODO|FIXME|XXX|BUG) ){0}
    (?<DATE> \\d{4}-\\d{2}-\\d{2} ){0}
    (?<FLAGS> [pts]:\\w+ ){0}
    (?<tag> (?&TAG) ) : \\s*
    (?<message> (?>[^\\s<]+[^\\n\\S]+)* [^\\s<]+ )? \\s* 
    <
    (?<author> (?: \\w{3} \\s* , \\s* )*+ \\w{3} )? \\s*
    (?<date> (?&DATE) )?
    (?<flags> (?&FLAGS) )?
    >
    $
"""
rgx = regex.compile(p, regex.VERBOSE | regex.MULTILINE)
How to write regex in Python with (?(DEFINE))?