【发布时间】:2020-03-25 21:49:28
【问题描述】:
我正在尝试创建一个在一个或多个日期拆分字符串的函数
{0: 'Stabilizing (P1 events)(11/5/19) -3.8.4\xa0released',
1: '(9/20/19)\-3.8.3 released; Enabled 100% for \xa0(released the APK to the store, not the actual app itself)',
2: '(11/12/19) Accepted & Released. Enabled 100% for.',
3: '(6/11/19) app released with feature flag disabled(9/11/19)\100% on for P1 events',
4: '(6/11/19) app released with feature flag disabled(9/11/19)\100% on for P1 events',
5: '(1/6/20)\xa0Released with feature flag disabled & LiveChannel bug fixed.\xa0(Live Channels disabled)(2/13/20)\xa0FireTv\xa0100% on for P1 events'}
例如,上例中的字符串 #3 将被拆分为:
['(6/11/19)', 'app released with feature flag disabled', '(9/11/19)', '100% on for P1 events']
我创建了另一个从每个字符串中提取日期的函数
def extract_comments_date(date):
val = re.findall('(\d+/\d+/\d+)', date)
if len(val) == 1:
return f"({val[0]})"
else:
return [f"({i})" for i in val]
extract_comments_date(mydict[3])
output: ['(6/11/19)', '(9/11/19)']
但现在我想知道如何在存储在列表中的多个分隔符(日期)上拆分字符串。
【问题讨论】:
-
尝试拆分:
\(\d{1,2}/\d{1,2}/\d{2,4}\)