New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
re.compile fails for verbose re with more than one group #37827
Labels
Comments
The third of the following three regular expressions [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 |
Logged In: YES The problem here is the '#' character in the third pattern. When using re.VERBOSE, it is taken as beginning a comment (unless preceeded by a backslash). Change that line to: .*:\s*(\#.*)?$ and the pattern will compile. |
Logged In: YES Ta. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: