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.

classification
Title: Including parentheses in a regular expression pattern enclosed by literal square bracket characters cause the square brackets not to be matched
Type: behavior Stage: resolved
Components: Versions: Python 3.6
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Farbod Safe2, SilentGhost, matrixise
Priority: normal Keywords:

Created on 2019-03-18 15:03 by Farbod Safe2, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (4)
msg338234 - (view) Author: Farbod Safe (Farbod Safe2) Date: 2019-03-18 15:03
Below two print statements should give the same results but they don't:

import re

s = '[a]'

print(*re.findall(r'\[.*]',s))
[a]

print(*re.findall(r'\[(.*)]',s))
a
msg338236 - (view) Author: Stéphane Wirtel (matrixise) * (Python committer) Date: 2019-03-18 15:07
3.6 is in security mode and not in bugfix mode.

Please, use 3.7.
msg338237 - (view) Author: Stéphane Wirtel (matrixise) * (Python committer) Date: 2019-03-18 15:07
Python 3.7.2 (default, Jan 16 2019, 19:49:22) 
[GCC 8.2.1 20181215 (Red Hat 8.2.1-6)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import re
>>> s = '[a]'
>>> print(*re.findall(r'\[.*]', s))
[a]
>>> print(*re.findall(r'\[.*]', s))
[a]
>>>
msg338239 - (view) Author: SilentGhost (SilentGhost) * (Python triager) Date: 2019-03-18 15:19
Fabrod, this has nothing to do with the square brackets. It is your assumption that the return value should be the same that is wrong. Cf.:

>>> re.findall(r'a.+', 'abc')
['abc']
>>> re.findall(r'a(.+)', 'abc')
['bc']

This is the correct documented behaviour.
History
Date User Action Args
2022-04-11 14:59:12adminsetgithub: 80530
2019-03-18 15:19:52SilentGhostsetresolution: out of date -> not a bug

messages: + msg338239
nosy: + SilentGhost
2019-03-18 15:07:34matrixisesetmessages: + msg338237
2019-03-18 15:07:15matrixisesetstatus: open -> closed

nosy: + matrixise
messages: + msg338236

resolution: out of date
stage: resolved
2019-03-18 15:03:59Farbod Safe2create