Passing a function to Powershell's (replace) function

前端 未结 2 1971
你的背包
你的背包 2020-11-30 13:39

I want to pass a function call(which returns a string) as a replacement string to Powershell\'s replace function such that each match found is replaced with a different stri

2条回答
  •  暖寄归人
    2020-11-30 14:27

    PowerShell does not (yet?) have support for passing a script block to the -replace operator. The only option here is to use [Regex]::Replace directly:

    [Regex]::Replace($mystring, 'match', {callback})
    

提交回复
热议问题