[issue1519638] Unmatched Group issue - workaround
Changes by Serhiy Storchaka storch...@gmail.com: -- assignee: - serhiy.storchaka ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1519638 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1519638] Unmatched Group issue - workaround
Roundup Robot added the comment: New changeset bd2f1ea04025 by Serhiy Storchaka in branch 'default': Issue 1519638: Now unmatched groups are replaced with empty strings in re.sub() https://hg.python.org/cpython/rev/bd2f1ea04025 -- nosy: +python-dev ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1519638 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1519638] Unmatched Group issue - workaround
Serhiy Storchaka added the comment: Thank you for your review Antoine. -- resolution: - fixed stage: patch review - resolved status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1519638 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1519638] Unmatched Group issue - workaround
Changes by Antoine Pitrou pit...@free.fr: -- assignee: effbot - ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1519638 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1519638] Unmatched Group issue - workaround
Serhiy Storchaka added the comment: Here is a patch which make unmatched groups to be replaced by empty string. These changes looks rather as new feature than bug fix and therefore can be applied only to 3.5. -- components: +Library (Lib) keywords: +patch nosy: +serhiy.storchaka stage: - patch review type: - enhancement versions: +Python 3.5 -Python 2.6, Python 2.7 Added file: http://bugs.python.org/file36650/re_sub_unmatched_group.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1519638 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1519638] Unmatched Group issue - workaround
Changes by irdb dalba.w...@gmail.com: -- nosy: +irdb ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1519638 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1519638] Unmatched Group issue - workaround
Nikki DelRosso nik...@gmail.com added the comment: I'm having the same issue as the original author of this issue was. The workaround does not apply to the situation where the captured text is on one side of an or grouping, rather than just being optional. I'm trying to remove groups of text in parentheses that come at the end of a string, but if the content in a pair of parentheses is a number, I want to retain it. My regular expression looks like so: These work: re.sub(r'(?:\((?:(\d+)|.*?)\)\s*)+$','\\1','avatar (2009)') 'avatar 2009' re.sub(r'(?:\((?:(\d+)|.*?)\)\s*)+$','\\1','avatar (2009) (special edition)') 'avatar 2009' This doesn't: re.sub(r'(?:\((?:(\d+)|.*?)\)\s*)+$','\\1','avatar (special Traceback (most recent call last): File stdin, line 1, in module File /usr/lib/python2.6/re.py, line 151, in sub return _compile(pattern, 0).sub(repl, string, count) File /usr/lib/python2.6/re.py, line 278, in filter return sre_parse.expand_template(template, match) File /usr/lib/python2.6/sre_parse.py, line 793, in expand_template raise error, unmatched group sre_constants.error: unmatched groupedition)') Is there some way I can apply this workaround to this situation? -- nosy: +Nikker ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1519638 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1519638] Unmatched Group issue - workaround
Nikki DelRosso nik...@gmail.com added the comment: Sorry, the non-working command should look as follows: re.sub(r'(?:\((?:(\d+)|.*?)\)\s*)+$','\\1','avatar (special edition)') -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1519638 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1519638] Unmatched Group issue - workaround
Matthew Barnett pyt...@mrabarnett.plus.com added the comment: The replacement can be a callable, so you could do this: re.sub(r'(?:\((?:(\d+)|.*?)\)\s*)+$', lambda m: m.group(1) or '', 'avatar (special edition)') -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1519638 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1519638] Unmatched Group issue - workaround
Nikki DelRosso nik...@gmail.com added the comment: Perfect; thank you! -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1519638 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1519638] Unmatched Group issue - workaround
Terry J. Reedy tjre...@udel.edu added the comment: If I understand This has been addressed in issue #2636., this issue should be closed as, perhaps, out-of-date or duplicate, with 2636 as superceder. Correct? -- nosy: +tjreedy versions: -Python 2.5, Python 3.0 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1519638 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1519638] Unmatched Group issue - workaround
Matthew Barnett pyt...@mrabarnett.plus.com added the comment: Issue #2636 resulted in the new regex module (also available on PyPI), so this issue is addressed by that, but there's no patch for the re module. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1519638 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1519638] Unmatched Group issue - workaround
Ezio Melotti ezio.melo...@gmail.com added the comment: It would be nice if you could port 'pieces' of #2636 to Python, in order to fix this and other bugs (and possibly add more features too). -- nosy: +ezio.melotti ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1519638 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1519638] Unmatched Group issue - workaround
Gerard g...@gp-net.nl added the comment: Matthew, Thanx for the heads-up! Regards, Gerard. ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1519638 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1519638] Unmatched Group issue - workaround
Matthew Barnett pyt...@mrabarnett.plus.com added the comment: This has been addressed in issue #2636. -- nosy: +mrabarnett ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1519638 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1519638] Unmatched Group issue - workaround
Gerard g...@gp-net.nl added the comment: Bobby, Can you post the actual text you need this for? The back ref indeed returns a None. I'm wondering if the regex can be be simplefied and if a positive lookbehind could solve this. Symantically speaking ... If there's a b then return the ar, because then an empty alternate might again be of help. Kind regards, Gerard. ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1519638 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1519638] Unmatched Group issue - workaround
Bobby Xiao nneon...@gmail.com added the comment: It was so long ago, I've since redone half my codebase (the hack is still there, but I can't remember what it was meant to replace now :( ). Sorry about that. ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1519638 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1519638] Unmatched Group issue - workaround
Bobby Xiao nneon...@gmail.com added the comment: Well, in this example the group (ar) is unmatched, so sre throws the error, and because of the alternation, the workaround you mentioned doesn't seem to directly apply. A better example is probably re.sub(foo(?:b(ar)|foo),\\1,foofoo) because this can't be simply repaired by refactoring the regex. The correct behaviour, as I have observed in other regex implementations, is to replace the group by the empty string; for example, in Javascript: 'foobar'.replace(/foo(?:b(ar)|baz)/,'$1') ar 'foobaz'.replace(/foo(?:b(ar)|baz)/,'$1') -- versions: +Python 2.5, Python 2.6, Python 3.0 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1519638 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1519638] Unmatched Group issue - workaround
Gerard g...@gp-net.nl added the comment: Dear Bobby, I don't see what would be the part that generates the empty string? Regards, Gerard. ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1519638 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1519638] Unmatched Group issue - workaround
Bobby Xiao nneon...@gmail.com added the comment: How would I apply that workaround to my example? re.sub(foo(?:b(ar)|baz),\\1,foobaz) ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1519638 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1519638] Unmatched Group issue - workaround
Changes by Jeffrey C. Jacobs [EMAIL PROTECTED]: -- nosy: +timehorse ___ Python tracker [EMAIL PROTECTED] http://bugs.python.org/issue1519638 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1519638] Unmatched Group issue - workaround
Changes by Jeffrey C. Jacobs [EMAIL PROTECTED]: -- versions: +Python 2.7 -Python 2.5 ___ Python tracker [EMAIL PROTECTED] http://bugs.python.org/issue1519638 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1519638] Unmatched Group issue - workaround
Brandon Mintern [EMAIL PROTECTED] added the comment: Looking at your code example, that solution seems quite obvious now, and I wouldn't even call it a workaround. Thanks for figuring this out. Now if I could only remember what code I was using that for... ___ Python tracker [EMAIL PROTECTED] http://bugs.python.org/issue1519638 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com