regexp和txt文件

时间:2012-01-16 15:51:17

标签: python regex

我有txt文件和正则表达式,似乎regexp工作,但我的尾部有多余的符号

reg = re.findall(r"Source RPM: [ \t\n\r]*(.*?) \s", stdout, re.DOTALL|re.MULTILINE|re.IGNORECASE)

在输出中我有

liblqr-0.4.1-5.src.rpm
Size
gwenhywfar-4.1.0-2.src.rpm
Size
texlive-20110705-1.src.rpm
Size
mandriva-theme-1.4.9-9.2.src.rpm
Size

['liblqr-0.4.1-5.src.rpm\nSize']
['gwenhywfar-4.1.0-2.src.rpm\nSize']
['texlive-20110705-1.src.rpm\nSize']
['mandriva-theme-1.4.9-9.2.src.rpm\nSize']

它是什么“nSize”?

1 个答案:

答案 0 :(得分:2)

你正在寻找一个不合适的搜索。 ('任何角色'),包括新线,直到满足空间。新行不是明确的空格('')字符,这就是为什么从正则表达式中删除它会使其工作。

r"Source RPM: [ \t\n\r]*(.*?)\s"
                             ^ removed ' '