我有一個文本文件。只有當文件名是.doc或.pdf類型文件時,我纔想得到包含文件名的行。使用python re.findall()
Python正則表達式查找行包含特定類型的文件名
例如,
<TR><TD ALIGN="RIGHT">4.</TD>
<TD ALIGN="LEFT" VALIGN="TOP" WIDTH=50%><a href="ABC.pdf"> On Complex Analytic Manifolds</a></TD>
<TD ALIGN="LEFT" VALIGN="TOP" WIDTH=72>L. Sam</TD>
</TR>
<TR><TD ALIGN="RIGHT">5.</TD>
<TD ALIGN="LEFT" VALIGN="TOP" WIDTH=50%><a href="DEF.doc"> On the Geometric theory of Fields</a>*</TD>
<TD ALIGN="LEFT" VALIGN="TOP" WIDTH=72>G.K. Ram</TD>
</TR>
我想以下行。
<TD ALIGN="LEFT" VALIGN="TOP" WIDTH=50%><a href="ABC.pdf"> On Complex Analytic Manifolds</a></TD>
<TD ALIGN="LEFT" VALIGN="TOP" WIDTH=50%><a href="DEF.doc"> On the Geometric theory of Fields</a>*</TD>
任何機構可以告訴我任何可擴展的方式在re.findall定義模式()?
like'href =「。+?\。(doc | pdf)' – georg
它只返回['pdf','doc'] ....但是我需要整行...... – mxant
嘗試用'搜索',而不是'findall' – georg