"10JAN2015AirMail standard envelope from HyderabadAddress details:John Cena Palm DriveAdelaide.Also Contained:NilAction Taken:Goods referred to HGI QLD for further action.Attachments:Nil34FEB2004"
我要做的是用python读取这个字符串,并分离连接的单词。我真正想要的是一个正则表达式来分隔字符串中的连接词。你知道吗
我想从一个文件中读取上面的字符串,输出应该如下所示:
"10 JAN 2015 AirMail standard envelope from Hyderabad Address details : John Cena Palm Drive Adelaide. Also calculated: Nil Action Taken: Goods referred to USG for further action. Attachments : Nil 60 FEB 2004."
(把连词分开)
我需要写一个正则表达式来分隔:
'10Jan2015AirMail', 'HyderabadAddress', 'details:John', 'DriveAdelaide'
需要一个正则表达式来识别像上面这样的连接词,并在同一个字符串中用空格分隔它们,像
'10 Jan 2015 AirMail, 'Hyderabad Address', 'details : John'
text = open('C:\sample.txt', 'r').read().replace("\n","").replace("\t","").replace("-","").replace("/"," ")
newtext = re.sub('[a-zA-Z0-9_:]','',text) #This regex does not work.Please assist
print text
print newtext
上面的代码不起作用
我知道这个解决方案可以做得非常简单,在集合中分类字符(上,下,数字),但我更喜欢做一个更详细的解决方案:
有时一个人只需要被指向正确的方向。你知道吗
相关问题 更多 >
编程相关推荐