Issue 14510: Regular Expression "+" perform wrong repeat (original) (raw)

Issue14510

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 bbbB is also a variable, but it\'s not BBBb') ['$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 主题: [] 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 主题: [] 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:28 admin set github: 58715
2012-04-06 13:46:20 tld5yj set messages: +
2012-04-06 13:38:37 tld5yj set messages: +
2012-04-06 01:41:04 ezio.melotti set status: open -> closedmessages: + assignee: ezio.melottiresolution: not a bugstage: resolved
2012-04-05 16:08:22 mrabarnett set messages: +
2012-04-05 13:47:46 tld5yj create