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

Named group regex error #51557

Closed
pythonmeister mannequin opened this issue Nov 11, 2009 · 2 comments
Closed

Named group regex error #51557

pythonmeister mannequin opened this issue Nov 11, 2009 · 2 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@pythonmeister
Copy link
Mannequin

pythonmeister mannequin commented Nov 11, 2009

BPO 7308
Nosy @mdickinson

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 2009-11-11.21:54:02.187>
created_at = <Date 2009-11-11.21:49:20.502>
labels = ['interpreter-core', 'invalid', 'type-bug', 'library']
title = 'Named group regex error'
updated_at = <Date 2009-11-11.21:54:02.177>
user = 'https://bugs.python.org/pythonmeister'

bugs.python.org fields:

activity = <Date 2009-11-11.21:54:02.177>
actor = 'mark.dickinson'
assignee = 'none'
closed = True
closed_date = <Date 2009-11-11.21:54:02.187>
closer = 'mark.dickinson'
components = ['Interpreter Core', 'Library (Lib)']
creation = <Date 2009-11-11.21:49:20.502>
creator = 'pythonmeister'
dependencies = []
files = []
hgrepos = []
issue_num = 7308
keywords = []
message_count = 2.0
messages = ['95152', '95153']
nosy_count = 2.0
nosy_names = ['mark.dickinson', 'pythonmeister']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = None
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue7308'
versions = ['Python 2.6']

@pythonmeister
Copy link
Mannequin Author

pythonmeister mannequin commented Nov 11, 2009

>>> import re
>>> p = re.compile(r'(P?<quotedstring>("[^"]*"))')
>>> p.match('"Hallo"')
>>> p = re.compile(r'("[^"]*")')
>>> p.match('"Hallo"')
<_sre.SRE_Match object at 0x0197F758>
>>> p.match('"Hallo"').group()
'"Hallo"'
>>> import sys
>>> sys.version
'2.6.3 (r263:75183, Oct  5 2009, 14:41:55) [MSC v.1500 32 bit (Intel)]'

When I use a named group like above, the regex does not match.
It otherwise does.
I could not find a hint in the docs, so I guess this behaviour is
not intended.

@pythonmeister pythonmeister mannequin added interpreter-core (Objects, Python, Grammar, and Parser dirs) stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Nov 11, 2009
@mdickinson
Copy link
Member

I think you want '(?P...', not '(P?...'.

Python 2.6.3 (r263:75183, Oct 16 2009, 15:14:21) 
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import re
>>> p = re.compile(r'(?P<quotedstring>("[^"]*"))')
>>> p.match('"Hallo"')
<_sre.SRE_Match object at 0x8a3c8>

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant