[Python] Regular expression for splitting mentions of two years appearing altogether

Discussão em 'Python' iniciado por Stack, Agosto 19, 2025.

  1. Stack

    Stack Membro Participativo

    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:cool:". How can I achieve my purpose?

    Continue reading...

Compartilhe esta Página