[Python] regex to find a pair of adjacent digits with different digits around them

Discussão em 'Python' iniciado por Stack, Março 6, 2025.

  1. Stack

    Stack Membro Participativo

    I want to find if there are two of the same digits next to each other, and the digit behind and in front of the pair is different.

    For example,

    123456678 should match as there is a double 6,

    1234566678 should not match as there is no double with different surrounding numbers. 12334566 should match because there are two 3s.

    So far i have this which works only with 1, and as long as the double is not at the start or end of the string, however I can deal with that by adding a letter at the start and end.

    ^.*([^1]11[^1]).*$


    I know I can use [0-9] instead of the 1s but the problem is having them all be the same digit.

    Continue reading...

Compartilhe esta Página