[Python] Python regular expression 'BA/BMF/ABCDEJF/

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

  1. Stack

    Stack Membro Participativo

    Need help with Regex expression, which i'm trying to work on. Below is the example that i'm trying to work on

    Code

    import re


    CommonPrefixes = [{'Prefix': 'BA/BMF/ABCDEJF/'}, {'Prefix': 'AG/CRBA_CORE/ABCDEJF/'}, {'Prefix': 'DC/KAT/pages-modified/'}]

    res = [re.sub("(^\w+/)|(^\w+\/|/)|(/$)",'',x["Prefix"]) for x in CommonPrefixes]

    print(res)


    Output I'm getting is below

    OutPut

    ['BMFABCDEJF', 'CRBA_COREABCDEJF', 'KATpages-modified']


    Output I'm looking for

    Expected output

    ['ABCDEJF', 'ABCDEJF', 'pages-modified']

    Continue reading...

Compartilhe esta Página