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: Regular Expression "+" perform wrong repeat
Type: behavior Stage: resolved
Components: Regular Expressions Versions: Python 3.2
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: ezio.melotti Nosy List: ezio.melotti, mrabarnett, tld5yj
Priority: normal Keywords:

Created on 2012-04-05 13:47 by tld5yj, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
CheckInconsistency.py tld5yj, 2012-04-05 13:47 Just used to check symbol inconsistency in two strings
Messages (5)
msg157588 - (view) Author: YunJian (tld5yj) Date: 2012-04-05 13:47
Regular expression perform wrong result, I use regular expression r'(\$.)+' try to match "$B$b" or something like that, but the script only give back "$b", r'(\$.){1,}', r'(\$.){2}' performed the same, you can take the file I attached for reference and run it, I try to solve it myself but failed, now I must use other ways to realize my aim, so appreciate for you help, thank you!
msg157600 - (view) Author: Matthew Barnett (mrabarnett) * (Python triager) Date: 2012-04-05 16:08
If a capture group is repeated, as in r'(\$.)+', only its last match is returned.
msg157632 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2012-04-06 01:41
>>> re.findall(r'((?:\$.)+)', 'This $b$B is also a variable, but it\'s not $B$b')
['$b$B', '$B$b']
msg157664 - (view) Author: YunJian (tld5yj) Date: 2012-04-06 13:38
Well, maybe I had never understood this though I use RE oftenly, this is the first time I met this and in my mind capture should not perform like this, thank you very much!

________________________________
 发件人: Matthew Barnett <report@bugs.python.org>
收件人: tld5yj@yahoo.com.cn 
发送日期: 2012年4月6日, 星期五, 上午 12:08
主题: [issue14510] Regular Expression "+" perform wrong repeat

Matthew Barnett <python@mrabarnett.plus.com> added the comment:

If a capture group is repeated, as in r'(\$.)+', only its last match is returned.

----------

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue14510>
_______________________________________
msg157665 - (view) Author: YunJian (tld5yj) Date: 2012-04-06 13:46
If that was caused by capture, I think I should learn and use it from start because it gave a result I didn't want but in the way I want, thank you very much, I will be more careful next time, thank you!

________________________________
 发件人: Ezio Melotti <report@bugs.python.org>
收件人: tld5yj@yahoo.com.cn 
发送日期: 2012年4月6日, 星期五, 上午 9:41
主题: [issue14510] Regular Expression "+" perform wrong repeat

Ezio Melotti <ezio.melotti@gmail.com> added the comment:

['$b$B', '$B$b']

----------
assignee:  -> ezio.melotti
resolution:  -> invalid
stage:  -> committed/rejected
status: open -> closed

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue14510>
_______________________________________
History
Date User Action Args
2022-04-11 14:57:28adminsetgithub: 58715
2012-04-06 13:46:20tld5yjsetmessages: + msg157665
2012-04-06 13:38:37tld5yjsetmessages: + msg157664
2012-04-06 01:41:04ezio.melottisetstatus: open -> closed
messages: + msg157632

assignee: ezio.melotti
resolution: not a bug
stage: resolved
2012-04-05 16:08:22mrabarnettsetmessages: + msg157600
2012-04-05 13:47:46tld5yjcreate