fork download
  1. import re
  2.  
  3. texts = ['1. 10.25% 2. 11% 3. 9.75% 4. 4.3%',
  4. '1.promising.2.inappropriately3.essential.4.itense.',
  5. '1. He has not been attending 2. English classes 3. since one month4. No error',
  6. '1. X got 15 shares2. B got 25 shares3. W got 54. shares.4. Mark got 2.5 shares']
  7.  
  8. pattern = r'(?<!\d){}\.'
  9. for text in texts:
  10. bps = []
  11. prev = 0
  12. for i in range(1,1000):
  13. rx = re.compile(pattern.format(i))
  14. m = rx.search(text, prev)
  15. if m:
  16. if prev != m.start():
  17. bps.append(text[prev:m.start()].strip())
  18. prev = m.start()
  19. else:
  20. break
  21. if prev < len(text) - 1:
  22. bps.append(text[prev:].strip())
  23. print(bps)
Success #stdin #stdout 0.02s 9504KB
stdin
Standard input is empty
stdout
['1. 10.25%', '2. 11%', '3. 9.75%', '4. 4.3%']
['1.promising.', '2.inappropriately', '3.essential.', '4.itense.']
['1. He has not been attending', '2. English classes', '3. since one month', '4. No error']
['1. X got 15 shares', '2. B got 25 shares', '3. W got 54. shares.', '4. Mark got 2.5 shares']