import re
text = '''
test login_id: userid
authority: root folder: root123
login password: 1234***
'''.lstrip()
data = [{k: v} for k, v in re.findall(r'\s*(.+?):\s+([^\s]+)', text)]
print(data)
# [{'test login_id': 'userid'}, {'authority': 'root'}, {'folder': 'root123'}, {'login password': '1234***'}]
metropolis
- 6,705
- 2
- 6
- 16