我正在尝试在 PowerShell 中替换包含括号的字符串。但是,当我尝试这样做时,它不起作用。
知道我哪里出错了吗?我应该做什么来替换包含的字符串()
with -replace
在 PowerShell 中?
$a='Some Text with (round) brackets. This text is long.'
$ch="with (round) brackets."
$b="this text"
$a -replace $ch,$b
Output:
Some Text with (round) brackets. This text is long.
-replace
useses 正则表达式所以你必须escape your regex
:
$a='Some Text with (round) brackets. This text is long.'
$ch="with (round) brackets."
$b="this text"
$a -replace [regex]::Escape($ch),$b
Output:
Some Text this text This text is long.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)