fork download
  1. import re
  2.  
  3. string = """
  4. Record ID: 9211
  5. User name: Administrator first
  6. User principal name: Administrator@example.com
  7. When created: 1999-12-23 3:8:52
  8. When changed: 2000-06-10 4:8:55
  9. Account expires: Never
  10. """
  11.  
  12. rx = re.compile(r'^(?P<key>[^:\n]+):\s*(?P<value>.+)', re.MULTILINE)
  13. result = {m.group('key'): m.group('value') for m in rx.finditer(string)}
  14. print(result)
  15.  
Success #stdin #stdout 0.02s 28384KB
stdin
Standard input is empty
stdout
[{'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'}]