以下打印123 $ replace456,我喜欢打印123yyy456。我如何在powershell中执行此操作?
$path = '123xxx456'
$search = "(\d*)xxx(\d*)"
$replace = 'yyy'
$path -replace $search, '$1$replace$2'
答案 0 :(得分:1)
为替换模式使用双引号字符串,以便$replace
正确展开。请记住在反向引用前逃离$
(即`$1
):
$path -replace $search, "`$1$replace`$2"