2016-07-16 33 views
-3

如何使用重新匹配以下模式?如何使用逗号来匹配模式?

2016-02-13 02:00:00.0,3525,http://www.heatherllindsey.com/2016/02/my-husband-left-his-9-5-job-for-good-it.html,158,0,2584490 

我用Python的split()功能属性分离出来,但由于数据庞大,工艺越来越因内存错误杀害。

+0

你应该是非常具体的,当谈到正则表达式。您没有提供任何尝试,我们无法确定您真正需要什么。 *只需使用'。+'来匹配这个字符串*对于这样一个模糊的问题是一个有效的答案。请澄清并添加您到目前为止编写的代码和正则表达式。 –

回答

0

如果你把长版的字符串会更好。 那么你怎么能做到这一点?这就是答案:

import re 
str = "2016-02-13 02:00:00.0,3525,http://www.heatherllindsey.com/2016/02/my-husband-left-his-9-5-job-for-good-it.html,158,0,2584490" 
pattern = re.compile("(.*?),", re.DOTALL) #we use re.DOTALL to continue splitting after endlines. 
result = pattern.findall(str) #we can't find the last statement (2584490) because of the pattern so we will apply second process 
pattern = re.compile("(.*?)", re.DOTALL) 
str2 = str[-50:-1]+str[-1] #we take last partition of string to find out last statement by using split() method 

result.append(str2.split(",")[-1]) 
print result 

它的工作原理...