[Python] How to replace string using regular expression in Python

Discussão em 'Python' iniciado por Stack, Junho 12, 2025.

  1. Stack

    Stack Membro Participativo

    I need help with replacing characters in a string using regular expressions.

    Input :

    s3 = ['March/21/2019' , 'Mar/23/2019']


    Desired Output :

    s3 = ['03/21/2019' , '03/23/2019']


    I tried a few things, but none work:


    1. s3 = s3.replace(r'Mar[a-z]*', '03')


      [*]
      s3 = s3.replace(r'(?:Mar[a-z]*)', '03')



    Continue reading...

Compartilhe esta Página