我试图简单地获取以下内容中冒号之后的所有内容:
hfarnsworth:204b319de6f41bbfdbcb28da724dda23然后是以下空格之前的所有内容:
29ca0a80180e9346295920344d64d1ce ::: 25basement这就是我所拥有的:
for line in f:
line = line.rstrip() #to remove \n
line = re.compile('.* ',line) #everything before space.
print line有什么建议可以给我指明正确的方向吗?谢谢!
另外,如果我想要返回匹配的字符串,re.compile是正确的函数吗?我也是python的新手。谢谢!!
发布于 2012-02-03 19:48:31
string = "hfarnsworth:204b319de6f41bbfdbcb28da724dda23"
print(string.split(":")[1:])
string = "29ca0a80180e9346295920344d64d1ce ::: 25basement"
print(string.split(" ")[0])https://stackoverflow.com/questions/9128055
复制相似问题