【发布时间】:2022-01-01 20:22:02
【问题描述】:
我基本上需要在接下来的6位数字和冒号之前分割一个字符串:
import re
my_str = '610640: 168 hours 610835: till next day 14:00 617041: 168 hours 611486:720 hours'
match = re.split(r'(\d{6}\:)', my_str)
print(match)
for item in match:
print(item)
阅读610640: 168 hours和610835: till next day 14:00和617041: 168 hours等等。我尝试过的其他正则表达式:
(\d{6}\:)+.*?(\d{6}\:)
我一直在使用https://pythex.org/ 来了解如何编写正则表达式
【问题讨论】:
标签: python-3.x regex