fork download
  1. import re
  2.  
  3. pattern = r"^name: .*(?:\n(?!name: ).*)*"
  4.  
  5. lines = """name: marvin
  6. attribute: one
  7. day: monday
  8. dayalt: test << this is a field that can sometimes show up
  9. name: judy
  10. attribute: two
  11. day: tuesday
  12. name: dot
  13. attribute: three
  14. day: wednesday
  15. """
  16.  
  17. matches = re.findall(pattern, lines, re.MULTILINE)
  18. print(matches)
Success #stdin #stdout 0.03s 9404KB
stdin
Standard input is empty
stdout
['name: marvin\nattribute: one\nday: monday\ndayalt: test    << this is a field that can sometimes show up', 'name: judy\nattribute: two\nday: tuesday', 'name: dot\nattribute: three\nday: wednesday\n']