Powershell 从 HTML 文件(或变量)中删除一段文本

Powershell to remove a block of text from an HTML file (or variable)

我有许多 HTML 文件,我正在尝试使用 powershell 删除特定的文本块。 此块出现在每个 table.

      <tr>
        <td colspan="3">
          <div id="reportbody">*TEXT*<a target="_blank" href=*LINK*</a></div>
        </td>
      </tr>

我可以在第 3 行执行 -replace 以停止 text/link 显示,但我在 table 中看到一个空白行。 我尝试过类似 post 的东西,但我没有独特的 start/finish 标记。 非常感谢任何帮助。

一种方式:

$regex = 
@'
(?ms)\s*<tr>\s*
\s*<td colspan="3">\s*
\s*<div id="reportbody">\*TEXT\*<a target="_blank" href=\*LINK\*</a></div>\s*
\s*</td>\s*
\s*</tr>\s*
'@



(Get-Content ./file.htm -raw) -replace $regex |
 Set-Content ./newfile.htm