fork download
  1. import re
  2. text = "/BENEF/FORNITURA GAS FEB-20 CIG Z9F 27D2198 01762-0000031"
  3. pattern = r'cig[\s:.]*(\S(?:\s*\S){9})(?!\S)'
  4. matches = re.finditer(pattern, text, re.I)
  5. for match in matches:
  6. print(re.sub(r'\s+', '', match.group(1)), ' found at ', match.span(1))
  7.  
Success #stdin #stdout 0.02s 9568KB
stdin
Standard input is empty
stdout
Z9F27D2198  found at  (32, 57)