2
I need to perform a query in a txt file in Python, but I have 2 problems due to interpretation of special characters.
When I insert | or \ the result is replaced: the | is addressed 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 do the string search FIM|2| inside a file, but anyway it returns true in the if and my intention is to return true only if the string contain FIM|2|.
|is an operator ofOU, try to change toFIM\|2\|. I mean, this wayFIM|2|you are looking for END or 2 or nothing. See the demo– danieltakeshi
That’s right, thank you very much !
– Eduardo Rafael Moraes
I had not accepted yet because I can only accept 10 min after he has answered, I would already accept, thank you!
– Eduardo Rafael Moraes