[Python] Regex: how to match all strings except when the pattern occurs at a specific position

Discussão em 'Python' iniciado por Stack, Julho 22, 2025.

  1. Stack

    Stack Membro Participativo

    I have a problem that would benefit greatly if I can include all matches of a pattern that do not occur at one specific index in a string. For example, if I want to match "ABC", except when it occurs in the 4th position of the string, I would need the following results:

    • ABCDEFGH (Match)
    • HABCDEFG (Match)
    • GHABCDEF (Match)
    • FGHABCDE (Don't Match)
    • EFGHABCD (Match)

    I have been reading about negative lookaheads and negative lookbehinds for a while now and cannot seem to find an example that fits my use case. Any help with this would be extremely appreciated.

    Continue reading...

Compartilhe esta Página