I have a test.ini
file with the following content:
[search]
pattern = ABC\d{2}-\d{3}
I need to use this pattern in a regular expression.
Therefore, I want to use configparser
to read the .ini file
import configparser
settings = configparser.ConfigParser()
settings.read("test.ini")
pattern = settings["search"]["pattern"]
but this does not give me the content regular expression string. It encodes \
as \\
.
pattern --> 'ABC\\d{2}-\\d{3}'
I want to replace the \\
with \
However:
pattern.replace("\\\\","\\")
does not work