我正在尝试在PowerShell中替换包含括号的字符串.但是,当我尝试这样做时,它无法正常工作.
知道我哪里出错了吗?什么是我该做的更换包含字符串()与-replace在PowerShell中?
$a='Some Text with (round) brackets. This text is long.'
$ch="with (round) brackets."
$b="this text"
$a -replace $ch,$b
Run Code Online (Sandbox Code Playgroud)
输出:
Some Text with (round) brackets. This text is long.
Run Code Online (Sandbox Code Playgroud)
-replace使用正则表达式,所以你必须逃避你的regex:
$a='Some Text with (round) brackets. This text is long.'
$ch="with (round) brackets."
$b="this text"
$a -replace [regex]::Escape($ch),$b
Run Code Online (Sandbox Code Playgroud)
输出:
Some Text this text This text is long.
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2202 次 |
| 最近记录: |