0

我正在尝试使用单个正则表达式命令消除两个特定文本字符串之间的所有文本。原文如下所示:

<html>
  <!-- template name: text.tpl -->
  <head>
    <title>Cross-Collection Search</title>    
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script src="/t/text/textclass.js" language="JavaScript"></script>
    <link rel="STYLESHEET" type="text/css" href="/t/text/textclass.css">
    <link rel="stylesheet" href="/t/text/textclass-specific.css" type="text/css">
    <script src="/t/text/bbagWindow.js" type="text/javascript" language="javascript"></script>
    <script type="text/javascript" language="javascript">
     <!-- 

     window.name = "mainwindow";

     //-->
    </script>    
  </head>

  <!-- -------------------------------------------------- -->

<body bgcolor="#FFFFFF" marginwidth="0" marginheight="0">

  <!-- -------------------------------------------------- -->

<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr> 
    <td height="54" class="hdrcolor" background="/t/text/graphics/hdr-bg1.gif">
    <a name="top"></a>
    <a href="http://ecfr.gpoaccess.gov/cgi/t/text/text-idx?c=ecfr;c=sampletc;cc=ecfr;xc=1;sid=75189253ab69c67a4a0484a5acb0c128;tpl=%2Fusr%2Flocal%2Fdlxs%2Fweb%2Ft%2Ftext%2Fhome.tpl" target="_top"><img src="/t/text/graphics/umdlt-smbanner.gif" border="0"></a></td>
     <td height="54" class="hdrcolor" align="right" valign="top" background="/t/text/graphics/hdr-bg2.gif">
      <table border="0" cellspacing="1" cellpadding="3">
        <tr>



          <td align="right" nowrap valign="top" bgcolor="#CCCCCC">&nbsp;<font size="-1"><a class="globnav" href="">Authorized user login</a></font>&nbsp;</td>
          <td align="right" bgcolor="#FFCC66" nowrap>&nbsp;<font size="-1"><a class="globnav" href="javascript:popupBBagWindow( 'http://ecfr.gpoaccess.gov/cgi/t/text/text-idx?c=ecfr;c=sampletc;cc=ecfr;xc=1;sid=75189253ab69c67a4a0484a5acb0c128;page=bbaglist' , true )">View 
            bookbag</a></font>&nbsp;</td>

        </tr>
      </table>
          <font class="navinfo" size="2"><br>your bookbag has <strong>0</strong> items</font>&nbsp;
    </td>
  </tr>

<!-- BEGIN rows outlining the navigation proper  -->

<!-- this row contains a table controlling layout for the top border lines of the navbar   -->

  <tr> 
    <td class="navcolor" colspan="2" align="left" height="1" nowrap>
    <table border="0" cellspacing="0" cellpadding="0">
        <tr> 
      <!-- home  -->
          <td width="70" height="1" align="center" nowrap><img src="/t/text/graphics/plug.gif" width="1" height="1" border="0"></td>        
          <td width="1"><img src="/t/text/graphics/plug.gif" width="1" height="1" border="0"></td>
      <!-- search  -->
          <td width="90" height="1" align="center" nowrap><img src="/t/text/graphics/plug.gif" width="1" height="1" border="0"></td>
      <td width="1"><img src="/t/text/graphics/plug.gif" width="1" height="1" border="0"></td> 
      <!-- browse -->
          <td width="75" height="1" align="center" nowrap><img src="/t/text/graphics/plug.gif" width="1" height="1" border="0"></td>
      <!-- blankspace  -->
      <td width="75" height="1" align="center" nowrap><img src="/t/text/graphics/plug.gif" width="1" height="1" border="0"></td>
      <!-- help  -->
      <td width="75" height="1" align="center" nowrap><img src="/t/text/graphics/plug.gif" width="1" height="1" border="0"></td>
        </tr></table>
    </td>
  </tr>


<!-- this row contains a table controlling layout for the nav tabs themselves   -->
  <tr> 
    <td class="navcolor" colspan="2" align="left" bgcolor="#666699" height="23" nowrap>
      <table border="0" cellspacing="0" cellpadding="0">
        <tr> 
          <!-- home  -->
          <td width="70" height="23" align="center" nowrap><font class="navlinks" color="#ffffff"><a href="http://ecfr.gpoaccess.gov/cgi/t/text/text-idx?c=ecfr;c=sampletc;cc=ecfr;xc=1;sid=75189253ab69c67a4a0484a5acb0c128;tpl=%2Fusr%2Flocal%2Fdlxs%2Fweb%2Ft%2Ftext%2Fhome.tpl" class="nav">Home</a></font></td>
          <!-- search  -->      
          <td width="90" height="23" align="center" nowrap><font class="navlinks" color="#000000"><a href="http://ecfr.gpoaccess.gov/cgi/t/text/text-idx?c=ecfr;c=sampletc;cc=ecfr;xc=1;sid=75189253ab69c67a4a0484a5acb0c128;page=simpleext" class="nav">Search</a></font></td >
           <!-- browse  -->

           <td width="90" height="23" align="center" nowrap><font class="navlinks" color="#ffffff"><a href="http://ecfr.gpoaccess.gov/cgi/t/text/text-idx?c=ecfr;cc=ecfr;xc=1;sid=75189253ab69c67a4a0484a5acb0c128;tpl=browse.tpl" class="nav">Browse</a></font></td >

          <!-- blankspace  -->
          <td width="50" height="23" align="center" nowrap>&nbsp;</td >
          <!-- help  -->
          <td width="70" height="23" align="center" nowrap><font class="navlinks" color="#ffffff"><a href="/t/text/help" target="helpwin" class="nav">Help</a></font></td >
        </tr>
      </table>
         </td >
        </tr>

<!-- this row contains the table that controls layout for the lower nav border lines   -->

<tr> 
    <td class="navhrcolor" colspan="2" align="left" height="1" nowrap bgcolor="#999999">
    <table border="0" cellspacing="0" cellpadding="0">
        <tr> 
          <td width="70" height="1" align="center" nowrap><img src="/t/text/graphics/plug.gif" width="1" height="1" border="0"></td>
          <td width="1"><img src="/t/text/graphics/plug.gif" width="1" height="1" border="0"></td>
          <td width="90" height="1" align="center" nowrap><img src="/t/text/graphics/plug.gif" width="1" height="1" border="0"></td>
          <td width="1"><img src="/t/text/graphics/plug.gif" width="1" height="1" border="0"></td>
          <td width="75" height="1" align="center" nowrap><img src="/t/text/graphics/plug.gif" width="1" height="1" border="0"></td>
          <td width="75" height="1" align="center" nowrap><img src="/t/text/graphics/plug.gif" width="1" height="1" border="0"></td>
        </tr></table>
    </td>
  </tr>
</table>

    <table cellspacing="0" cellpadding="5" width="100%">
      <tr> 
        <td valign="top" nowrap>



    <hr size="1">
    </td>
   </tr>
</table>

    <table cellspacing="0" cellpadding="15">
      <tr> 
        <td>    

          <br>
<strong><span class=mainheader>

正则表达式搜索和替换后的完整文本需要如下所示:

<html>
<strong><span class="mainheader"> 

出于某种原因,仅使用以下内容是行不通的。为什么?

<html>(.*)<strong><span class=mainheader>
4

1 回答 1

2

您可能需要全点模式(以.匹配换行符),或者只是替换.[\s\S](确保所有字符都匹配,无论您的语言是否支持全点模式)。

于 2012-07-07T03:39:10.260 回答