提取两个字符之间的所有字符串 powershell

extract all the strings between two characters powershell

以下是两个角色。 1. {{ 2. }} 我试图在以下文件中找到这些字符之间的所有字符串。

    <add key="CSDFG_SqlServerFailOverInterval" value="{{environment}}"/>
    <add key="CSDFG_JobResetInterval" value="600000"/>
    <add key="FileTypeFilter" value="{{filetype}}"/>

我正在使用以下 powershell 命令,

$x = C:\app.config
$s = Get-Content $x
$prog = [regex]::match($s,'{{([^/)]+)}}').Groups[1].Value
write-host $prog

而我的输出只是一个字符串。它并没有牵动所有的弦。有人可以建议我如何获得所有字符串。提前致谢。

[regex]::Match() 仅 returns 第一个 匹配。使用 [regex]::Matches() 捕获所有匹配项:

$s = Get-Content 'C:\app.config'
[regex]::Matches($s, '{{([^/)]+)}}') |ForEach-Object { $_.Groups[1].Value }