This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author nedbat
Recipients ezio.melotti, mrabarnett, nedbat
Date 2022-03-30.11:49:35
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1648640975.38.0.120656824245.issue47163@roundup.psfhosted.org>
In-reply-to
Content
In this code, the same regex is compiled with and without re.VERBOSE.  Without, it compiles fine.  With, it fails with an "unterminated subpattern" error.

    list_num_rx1 =     r"""(?P<paren>\()?(\d+|#|[a-z])(?(paren)\)|\.)"""
    list_num_rx2 = r"""(?x)(?P<paren>\()?(\d+|#|[a-z])(?(paren)\)|\.)"""
    
    # This works:
    re.compile(list_num_rx1)
    # Either of these fails:
    re.compile(list_num_rx1, flags=re.VERBOSE)
    re.compile(list_num_rx2)

(What I really wanted was this, but the error happens without the multiline string:)

    list_num_rx = r"""(?x)
        (?P<paren>\()?          # maybe an opening paren
        (\d+|#|[a-z])           # the number: 123, or #, or a-z
        (?(paren)               # if we had an opening paren..
            \)|                 #   then we need a closing paren
            \.                  #   otherwise a dot.
        )
        """
History
Date User Action Args
2022-03-30 11:49:35nedbatsetrecipients: + nedbat, ezio.melotti, mrabarnett
2022-03-30 11:49:35nedbatsetmessageid: <1648640975.38.0.120656824245.issue47163@roundup.psfhosted.org>
2022-03-30 11:49:35nedbatlinkissue47163 messages
2022-03-30 11:49:35nedbatcreate