re.sub and empty groups

Patrick Gaherty pgaherty at chambersharrap.co.uk
Tue Feb 12 10:56:02 EST 2002


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




More information about the Python-list mailing list