>>423
なんで変数の対応がめちゃくちゃなの?
正規表現で力技でやるとこんなところだが
xmlとして読み込めばnode削除でいけそうな気がする
Add-Type -AssemblyName Microsoft.VisualBasic
$html = Get-Content "D:\Download\test\sample.html" -Raw

# KWクラスdivを正規表現で削除
$pattern = [regex]"^((?:(?'open'<div[^>]*?>[\r\n]*))|(?'close-open'</div>)|(?:(?!</?div[^>]*>)[\s\S])+?)*(?(open)(?!))"
$processedHtml=$pattern.replace($html,{
$r=$args.value
$e=0
$args.groups['3'].captures|
sort index|
?{$_.index+$_.length -gt $e -and $_.value -cmatch '<div.*class="KW"'}|
%{$e=$_.index+$_.length; $r=[Microsoft.VisualBasic.Strings]::replace($r,$_.value,"",1,1)}
$r
})
$processedHtml | Out-File "D:\Download\test\pit.html" -Encoding UTF8