fork download
  1. import re
  2.  
  3.  
  4. testes = ("Vini12cius 000.000.000-00",
  5. "Vini12cius 00000000000",
  6. "Vinicius12 00000000000",
  7. "12Vinicius 00000000000",
  8. "000.000.000-00 Vini12cius",
  9. "00000000000 Vini12cius",
  10. "00000000000 Vinicius12",
  11. "00000000000 12Vinicius")
  12.  
  13.  
  14. padrao_regex = re.compile(r"(\d+)(?=[a-zA-Z]+)|(?<=[a-zA-Z])(\d+)")
  15. substituicoes = [re.sub(padrao_regex, "", elemento_teste) for elemento_teste in testes]
  16. if substituicoes:
  17. for substituicao in substituicoes:
  18. print(substituicao)
Success #stdin #stdout 0.04s 27712KB
stdin
Standard input is empty
stdout
Vinicius 000.000.000-00
Vinicius 00000000000
Vinicius 00000000000
Vinicius 00000000000
000.000.000-00 Vinicius
00000000000 Vinicius
00000000000 Vinicius
00000000000 Vinicius