I'm trying something along the following lines: line = re.sub(r'(a)(b)?(c)',r'\3\2\1',line) and Python complains about empty groups when (b)? doesn't match. What's the best way of getting around this? Thanks in advance. Patrick Gaherty