我的问题与之前在Python Reverse Find in String上发表的问题类似
以下是我的超长字符串示例:
t1 = '''1281674 the crescent annandale 02/10/2019 16/10/2019 - 16/11/2019 pending 1281640 city west link rd lilyfield 02/10/2019 16/10/2019 - 16/11/2019 pending 1276160 victoria rd rozelle 25/09/2019 14/10/2019 - 15/10/2019 pending 1331626 31/12/2019 - 31/01/2020 incomplete n/a 1281674 the crescent annandale 02/10/2019 16/10/2019 - 16/11/2019'''
更新日期:2020年2月1日
在放入数据帧之前,我将数据分组到列表中。我不想要任何与'incomplete n/a'
相关的数据。我是否需要删除字符串,或者是否有一个正则表达式函数来识别其位置上的'incomplete n/a'
和组
我想要两个输出:
ONE此列表t1L = ['1281674 ', '1281640 ', '1276160 ']
。请注意,这不包括1331626
TWO此字符串将被拆分或重新定义(不包含1331626),例如:
t1 = '''1281674 the crescent annandale 02/10/2019 16/10/2019 - 16/11/2019 pending 1281640 city west link rd lilyfield 02/10/2019 16/10/2019 - 16/11/2019 pending 1276160 victoria rd rozelle 25/09/2019 14/10/2019 - 15/10/2019 pending'''
谢谢你的帮助
您需要2个正则表达式才能获得2个列表:
输出:
Demo & explanation
您可以使用循环和条件尝试以下代码
我认为你的问题有可行的代码
new_str = t1[:t1.find(re.findall('\d{7}', t1[:t1.find('incomplete n/a')])[-1])])
相关问题 更多 >
编程相关推荐