Skip to content
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

Closed
gcorral mannequin opened this issue Jan 24, 2003 · 3 comments
Closed

re.compile fails for verbose re with more than one group #37827

gcorral mannequin opened this issue Jan 24, 2003 · 3 comments

Comments

@gcorral
Copy link
Mannequin

gcorral mannequin commented Jan 24, 2003

BPO 674264
Nosy @mwhudson

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:

assignee = None
closed_at = <Date 2003-02-05.14:12:56.000>
created_at = <Date 2003-01-24.20:36:28.000>
labels = ['expert-regex', 'invalid']
title = 're.compile fails for verbose re with more than one group'
updated_at = <Date 2003-02-05.14:12:56.000>
user = 'https://bugs.python.org/gcorral'

bugs.python.org fields:

activity = <Date 2003-02-05.14:12:56.000>
actor = 'mwh'
assignee = 'effbot'
closed = True
closed_date = None
closer = None
components = ['Regular Expressions']
creation = <Date 2003-01-24.20:36:28.000>
creator = 'gcorral'
dependencies = []
files = []
hgrepos = []
issue_num = 674264
keywords = []
message_count = 3.0
messages = ['14199', '14200', '14201']
nosy_count = 4.0
nosy_names = ['mwh', 'effbot', 'glchapman', 'gcorral']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = None
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue674264'
versions = ['Python 2.2']

@gcorral
Copy link
Mannequin Author

gcorral mannequin commented Jan 24, 2003

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

@gcorral gcorral mannequin closed this as completed Jan 24, 2003
@gcorral gcorral mannequin added the invalid label Jan 24, 2003
@gcorral gcorral mannequin assigned effbot Jan 24, 2003
@gcorral gcorral mannequin added the topic-regex label Jan 24, 2003
@gcorral gcorral mannequin closed this as completed Jan 24, 2003
@gcorral gcorral mannequin added the invalid label Jan 24, 2003
@gcorral gcorral mannequin assigned effbot Jan 24, 2003
@gcorral gcorral mannequin added the topic-regex label Jan 24, 2003
@glchapman
Copy link
Mannequin

glchapman mannequin commented Feb 5, 2003

Logged In: YES
user_id=86307

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.

@mwhudson
Copy link

mwhudson commented Feb 5, 2003

Logged In: YES
user_id=6656

Ta.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant