【发布时间】:2018-01-10 00:46:25
【问题描述】:
给定一个分隔符数组:
columns = ["Name:", "ID:", "Date:", "Building:", "Room:", "Notes:"]
还有一个字符串,其中一些列留空(并且有随机空格):
input = "Name: JohnID:123:45Date: 8/2/17Building:Room:Notes: i love notes"
我怎样才能得到这个:
["John", "123:45", "8/2/17", "", "", "i love notes"]
我尝试简单地删除子字符串以查看我可以从那里去哪里,但我仍然卡住了
import re
input = re.sub(r'|'.join(map(re.escape, columns)), "", input)
【问题讨论】: