[Python] Matching blocks of text

Discussão em 'Python' iniciado por Stack, Dezembro 8, 2024.

  1. Stack

    Stack Membro Participativo

    I have some text that looks like so,

    PIN ABC
    DIRECTION IN;
    PORT
    RECT 10 20 20 40;
    END
    END ABC

    PIN ABC2
    DIRECTION OUT;
    PORT
    RECT 10 20 20 40;
    END
    END ABC2


    I need to extract the block of PIN definition that lives between PIN xxx and END xxx. I am trying to parse the text file with regex and I am not getting the desired result since I have nested END statement.

    with open(f,'r') as fh:
    all = fh.read()
    re.search('PIN(.*)END', all, re.DOTALL)


    I really need to search for PIN xxx and END xxx as block markers

    Is there a way

    Continue reading...

Compartilhe esta Página