[Python] Extract subtring using regex python

Discussão em 'Python' iniciado por Stack, Fevereiro 7, 2025.

  1. Stack

    Stack Membro Participativo

    Hello I have this string and I need extract from this some sub strings according some delimiters:

    string = """
    1538 a
    123
    skua456
    789
    5
    g
    15563 blu55g
    b
    456
    16453 a
    789
    5
    16524 blu
    g
    55
    1734 a
    987
    987
    55
    aasf
    552
    18278 blu
    ttry
    """


    And I need extract exactly this strings:

    string1 =
    """
    1538 a
    123
    skua456
    789
    5
    g
    15563 blu55g
    """


    string2 = """
    16453 a
    789
    5
    16524 blu
    """


    string3 =
    """
    1734 a
    987
    987
    55
    aasf
    552
    18278 blu
    """


    I have tried a lot of types: re.findall, re.search, re.match. But I never geted the result expected.

    For eg: this code bellow print all string:

    re.split(r"a(.*)blu", a)[0]

    Continue reading...

Compartilhe esta Página