为了澄清标题,我试图在html文档中找到一行,其中包含以下字符串(或一些接近的变体):
<!--Copy from here-->
并且只包含一个唯一的文件名。我们称之为SN12345.htm
我正在搜索的文档有几行,我很难在'copy'字符串之间隔离一行。以下正则表达式几乎匹配整个文档(打开单行标记):
\<!-+Copy [A-Za-z ]+-+\>(.*SN12345\.htm.*)\<!-+Copy [A-Za-z ]+-+\>
我想要的是它只匹配文件名后面第一次出现的复制字符串。我该怎么做呢?我正在使用Python。
以下是一个示例输入:
<!--Copy from here-->
<TR valign=top>
<TD><A href="SN_2100-24.htm">2100-24</A></TD>
<TD>2100 Bioanalyzer - peak find problem when using new Ambion RNA ladder Cat. #7152</TD>
<TD>11/04</TD><td valign=top><p align="center">I</p></td></tr>
<!--Copy from here-->
<TR valign=top>
<TD><A href="SN_2100-23.htm">2100-23</A></TD>
<TD>2100 Bioanalyzer communication problems when both Biosizing and 2100 Expert SW are active</TD>
<TD>10/04</TD><td valign=top><p align="center">I</p></td></tr>
<!--Copy from here-->
<TR valign=top>
<TD><A href="SN_2100-22.htm">2100-22</A></TD>
<TD>Incompatibility of 2100 Expert and Microsoft Windows XP Service Pack 2</TD>
<TD>09/04</TD><td valign=top><p align="center">I</p></td></tr>
<!--Copy from here-->
<TR valign=top>
<TD><A href="SN_2100-21.htm">2100-21</A></TD>
<TD>2100 Bioanalyzer - DNA LabChip Kits and detergent containing PCR buffer</TD>
<TD>04/04</TD><td valign=top><p align="center">I</p></td></tr>
<!--Copy from here-->
<TR valign=top>
<TD><A href="SN_2100-20.htm">2100-20</A></TD>
<TD>General PC system and settings requirements for 2100 expert software</TD>
<TD>04/04</TD><td valign=top><p align="center">I</p></td></tr>
<!--Copy from here-->
<TR valign=top>
<TD>2100-19</A></TD>
<TD>not used</TD>
<TD>01/04</TD><td valign=top><p align="center">I</p></td></tr>
<!--Copy from here-->
<TR valign=top>
<TD><A href="SN_2100-18.htm">2100-18</A></TD>
<TD>RNA 6000 Pico Kits - ART® Aerosol Resistant Tips generate baseline abnormalities</TD>
<TD >01/04</TD><td valign=top><p align="center">I</p></td></tr>
<!--Copy from here-->
答案 0 :(得分:1)
假设XX = <!--Copy[^-]*-->
和正则表达式在下面:
XX(?:(?!XX)[\s\S])*SN12345\.htm(?:(?!XX)[\s\S])*XX
||^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^||
您会看到重复的模式存在。两端的两个XX
定义了匹配应该开始和结束的边界。然后有(?:(?!XX)[\s\S])*
我将解释:
(?:
启动非捕获组
(?!XX)
否定前瞻,后续字符不应为XX
[\s\S]
如果之前的模式断言,则提前一步)*
小组结束,尽可能多地重复