fork download
  1. import re
  2.  
  3. pattern = r"\b\d{8}\b.*?(?=\s*(?:\b\d{8}\b|$))"
  4. s = "12345678 abcdefg 37394822 gdzdnhqihdzuiew 09089799 78998728 gdjewdwq"
  5.  
  6. print(re.findall(pattern, s))
Success #stdin #stdout 0.03s 9612KB
stdin
Standard input is empty
stdout
['12345678 abcdefg', '37394822 gdzdnhqihdzuiew', '09089799', '78998728 gdjewdwq']