[Python] Matching end of string or ; in regex

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

  1. Stack

    Stack Membro Participativo

    Why does the following regex not match the last occurrence of the search word?

    (?i)(^|,|;)\s*old\s*($|;)


    This matches the first and second old, but not the third:

    One,old;Two,old;old
    ^ ^ ^
    match match \_ no match


    However, if I remove the last ; ((?i)(^|,|;)\s*old\s*$), it does match the last occurrence.

    P.S. I'm using Python.

    Continue reading...

Compartilhe esta Página