PowerShell替换两个字符串之间的文本

时间:2017-08-24 08:45:44

标签: regex powershell

我正在尝试修改config.xml config.xml内容

<command>
some lines here 2
</command>
some lines here 3

所以我想替换&lt; command></command>之间的内容。这是我尝试做的事情

$Replace = Get-Content D:\Temp\Replace.txt
$ReplaceWith = Get-Content D:\Temp\ReplaceWith.txt

$regex = '(<command>\d*).*?(</command>\d*)'
$Replace -replace $regex, $ReplaceWith

但它不起作用。需要帮助。

1 个答案:

答案 0 :(得分:0)

感谢gms0ulman。我能够在powershell中使用read作为xml,下面是代码

Sheet1.MyListBox.Selected(0) = True