你可以试试这个正则表达式:
(\w+): *([\w\\\/\- \.\@\_\| ]+)([^\w:]|$)
但你也必须把它剥掉
import re
my_string = 'address: 123 fake street city: new york state: new york population: 500000'
{ x.group(1): x.group(2).strip() for x in re.finditer(r'(\b\w+\b): *([\w\\\/\- \.\_\|\@ ]+)([^\w:]|$)', my_string)}
â
结果:
{'address': '123 fake street',
'city': 'new york',
'state': 'new york',
'population': '500000'}