1
How could I get just the digits of that string?
<SCANNER A7899739503929>
I’ve tried using the findall
, but unsuccessfully it returns me several separate numbers:
import re
txt = open("P:/portal/cupons/sco/sc_op.024_10_06.txt", "r+").read()
# usando finditer ele retorna a posição da palavra
# Localiza o inicio do cupom
x = re.finditer(r"CAIXA.*", txt)
# Localiza o fim do cupom
z = re.finditer(r"SUBTOTAL.*", txt)
espelhos = list(zip(x, z))
# Testando o valor específico para cada espelho
for espelho in espelhos:
txt_espelho = txt[espelho[0].span()[0]: espelho[1].span()[1] + 1]
print('===================================================================================================================================')
codigos = re.findall(r"<SCANNER.*", txt_espelho)
print(codigos)
These are the separate codes:
<SCANNER A7891203021106>', '<SCANNER A7891203021106>', '<SCANNER A7891203021304>', '<SCANNER A7891203021304>', '<SCANNER A7891962036984>'
How can I get just the numbers?
Perfect , however they are all coming glued , would have to separate each code ?
– I Need Coffe
There’s always... I believe the variable
codigos
is a string list, right? So use the last example withcodigos
instead oflista
– Paulo Marques