summaryrefslogtreecommitdiff
path: root/Lib/sre_parse.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2014-10-10 11:06:31 +0300
committerSerhiy Storchaka <storchaka@gmail.com>2014-10-10 11:06:31 +0300
commit7438e4b56fa6a34a021f11e1220331e841419b96 (patch)
tree5adea0024d47e6816a9e771423e247faeffab0f6 /Lib/sre_parse.py
parent365e28238f3ccde7f9024a37c212381746748d54 (diff)
downloadcpython-git-7438e4b56fa6a34a021f11e1220331e841419b96.tar.gz
Issue 1519638: Now unmatched groups are replaced with empty strings in re.sub()
and re.subn().
Diffstat (limited to 'Lib/sre_parse.py')
-rw-r--r--Lib/sre_parse.py8
1 files changed, 3 insertions, 5 deletions
diff --git a/Lib/sre_parse.py b/Lib/sre_parse.py
index b9a1852823..063d1b7fda 100644
--- a/Lib/sre_parse.py
+++ b/Lib/sre_parse.py
@@ -880,14 +880,12 @@ def parse_template(source, pattern):
def expand_template(template, match):
g = match.group
- sep = match.string[:0]
+ empty = match.string[:0]
groups, literals = template
literals = literals[:]
try:
for index, group in groups:
- literals[index] = s = g(group)
- if s is None:
- raise error("unmatched group")
+ literals[index] = g(group) or empty
except IndexError:
raise error("invalid group reference")
- return sep.join(literals)
+ return empty.join(literals)