fork download
  1. import re
  2.  
  3. pattern = r"(?<!\S)\d+\.\s((?:\d+\.\s)*[^\s.,:!?]+)"
  4. strings = [
  5. "1. text",
  6. "2. wordX wordY.",
  7. "3. 4. wordZ."
  8. ]
  9.  
  10. for s in strings:
  11. for m in re.finditer(pattern, s):
  12. print(m.group(1).split(". "))
Success #stdin #stdout 0.01s 7108KB
stdin
Standard input is empty
stdout
['text']
['wordX']
['4', 'wordZ']