将下午4点分为下午4点和下午2点30分,下午2点30分在python中

时间:2017-02-07 11:40:55

标签: python-3.x anaconda

我正在尝试制作一个简单的函数来分割数字和alpha,

e.g: &#34;日期:16.06.2016开始时间(带时区):2:30pm 4:00Pm 结束时间(带时区)&#34; < / p>

代码后: &#34;日期:16.06.2016开始时间(带时区):下午2:30 4:00 Pm 结束时间(带时区)&#34 ;

    enter code here

x="Date : 16.06.2016 Start Time (with time zone) :2:30pm to 4:00Pm End Time (with time zone)"
p = re.compile("([0-9])([([a-z])")

for m in p.findall(x):

      print (m)

1 个答案:

答案 0 :(得分:0)

您可以使用:

import re
y=re.sub("(?<=[a-zA-Z])(?=[0-9])|(?<=[0-9])(?=[a-zA-Z])", " ", x)
z=re.sub("(?<=\s):(?=[0-9])", " : ", y)