Skip to main content
3 / 4
本文から 55 文字削除
metropolis
  • 6,705
  • 2
  • 6
  • 16
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