[Python] How can I display raw string of regex with ValueError in python?

Discussão em 'Python' iniciado por Stack, Maio 26, 2025.

  1. Stack

    Stack Membro Participativo

    I would like to display raw string of regex expression as it looks. I works with print but it does not work with ValueError. How can I display raw string of regex expression as it looks with ValueError?

    pattern = r"\\d\{(\d+)\}"
    print(f"pattern with print ={pattern}")
    raise ValueError(f"pattern with ValueError ={pattern}")


    The followings are outputs.

    pattern with print =\\d\{(\d+)\}
    pattern with ValueError =\\\\d\\{(\\d+)\\}"

    Continue reading...

Compartilhe esta Página