代码语言:javascript复制
import re
headers_str = '''
formhash: f0f241b5
qdxq: nu
qdmode: 2
todaysay:
fastreply: 0
'''
pattern = '^(.*?): (.*)$'
for line in headers_str.splitlines():
print(re.sub(pattern, ''\1': '\2',', line))