import re pattern = r"^name: .*(?:\n(?!name: ).*)*" lines = """name: marvinattribute: oneday: mondaydayalt: test << this is a field that can sometimes show upname: judyattribute: twoday: tuesdayname: dotattribute: threeday: wednesday""" matches = re.findall(pattern, lines, re.MULTILINE)print(matches)
Standard input is empty
['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']
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!