import re string = """ Record ID: 9211 User name: Administrator first User principal name: Administrator@example.com When created: 1999-12-23 3:8:52 When changed: 2000-06-10 4:8:55 Account expires: Never """ rx = re.compile(r'^(?P<key>[^:\n]+):\s*(?P<value>.+)', re.MULTILINE) result = {m.group('key'): m.group('value') for m in rx.finditer(string)} print(result)
Standard input is empty
[{'key': 'Record ID', 'value': '9211'}, {'key': 'User name', 'value': 'Administrator first'}, {'key': 'User principal name', 'value': 'Administrator@example.com'}, {'key': 'When created', 'value': '1999-12-23 3:8:52'}, {'key': 'When changed', 'value': '2000-06-10 4:8:55'}, {'key': 'Account expires', 'value': 'Never'}]