I need to perform a query in a txt file in Python, however I have 2 problems due to the interpretation of special characters.
When I enter |
or \
the result ends up being replaced: |
is interrupted as white space and \
is duplicated ( \
).
import re
erro = r"FIM|2|"
linha = 'ahsuasaudsdad '
if re.search(erro, linha):
print('Não deveria cair aqui')
print(re.findall(erro, linha))
In this case, I search the string FIM|2|
within a file, but anyway it returns true
in if
and my intention is to return true
only if string
contains FIM|2|
.