[issue30720] re.sub substitution match group contains wrong value after unmatched pattern was processed
Serhiy Storchaka
report at bugs.python.org
Wed Jun 21 02:54:30 EDT 2017
Serhiy Storchaka added the comment:
Atomic groups can help you: '<div>((?><p>.*?</p>))</div>'.
But this feature is not supported in the re module yet (see issue433030). You can use the third-party regex module which is compatible with the re module and supports atomic grouping.
>>> import regex as re
>>> pattern = re.compile('<div>((?><p>.*?</p>))</div>', flags=re.DOTALL)
>>> print(re.sub(pattern, '\\1',
... '<div><p>foo</p>123456789</div>\n'
... '<div><p>bar</p></div>\n'))
<div><p>foo</p>123456789</div>
<p>bar</p>
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue30720>
_______________________________________
More information about the Python-bugs-list
mailing list