[Python-bugs-list] [ python-Bugs-674264 ] re.compile fails for verbose re with more than one group

SourceForge.net noreply@sourceforge.net
Fri, 24 Jan 2003 12:36:28 -0800


Bugs item #674264, was opened at 2003-01-24 20:36
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=674264&group_id=5470

Category: Regular Expressions
Group: Python 2.2.1
Status: Open
Resolution: None
Priority: 5
Submitted By: Garth Corral (gcorral)
Assigned to: Fredrik Lundh (effbot)
Summary: re.compile fails for verbose re with more than one group

Initial Comment:
The third of the following three regular expressions
fails to compile with "unbalanced parenthesis" error:


[foo.py]

import re

_good_re =
re.compile(r'\s*(elif|else|except|finally).*:\s*(#.*)$')

_also_good_re = re.compile(r'''
    \s*
    ( elif
    | else
    | except
    | finally
    )
    .*:
''', re.VERBOSE)

_bad_re = re.compile(r'''
    \s*
    ( elif
    | else
    | except
    | finally
    )
    .*:\s*(#.*)?$
''', re.VERBOSE)


>>> import foo
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "zzz.py", line 15, in ?
    _bad_re = re.compile(r'''
  File "/usr/local/lib/python2.2/sre.py", line 178, in
compile
    return _compile(pattern, flags)
  File "/usr/local/lib/python2.2/sre.py", line 228, in
_compile
    raise error, v # invalid expression
sre_constants.error: unbalanced parenthesis


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=674264&group_id=5470