Issue 1519638: Now unmatched groups are replaced with empty strings in re.sub()
and re.subn().
diff --git a/Lib/sre_parse.py b/Lib/sre_parse.py
index b9a1852..063d1b7 100644
--- a/Lib/sre_parse.py
+++ b/Lib/sre_parse.py
@@ -880,14 +880,12 @@
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)