fork download
  1. import re
  2. test_str = "test 1:\nhello op1 yviphf\nhello op2 vipqwe\ntest 2:\nhello op3\nhello op4 vipgt\nhello op5 zcv"
  3. res1 = [y for y in re.findall(r'test\s*(\d+)', test_str) if y]
  4. res2= [re.findall(r'(?m)^hello\s*(\S+)', b) for b in re.split(r'test\s*\d+', test_str) if b]
  5. print (zip(res1, res2))
  6.  
  7.  
Success #stdin #stdout 0.01s 9016KB
stdin
Standard input is empty
stdout
[('1', ['op1', 'op2']), ('2', ['op3', 'op4', 'op5'])]