I have the following case, where in my string I have improperly formatted mentions of the form "(19561958)" that I would like to split into "(1956-1958)". The regular expression that I tried is: import re a = "(19561958)" re.sub(r"(\d\d\d\d\d\d\d\d)", r"\1-", a) but this returns me "(1956195". How can I achieve my purpose? Continue reading...