https://bugzilla.wikimedia.org/show_bug.cgi?id=55184
--- Comment #2 from Kunal Mehta (Legoktm) legoktm.wikipedia@gmail.com --- This regex here is just an example, and probably a bad one (as the regex it does nothing by this replacement). Your suggestion regarding the specific regex (to use inner optional group within group) would probably fix this specific regex, but this is workaround - replace.py should support replacing capturing optional capturing group the same way re.findall behaves.
The behaviour of replacing None to empty string is compatible with the behaviour of re.findall (re.findall('a(b)?(c)','ac') => [('', 'c')]) and with regex engines of most languages (in JS: 'ac'.replace(/a(b)?(c)/,'a$1c')), though python re isn't consistent here (re.sub('a(b)?(c)','X\\1','ac') - is error).