我想使用正则表达式进行匹配,并使用将要使用子组作为键在表中查找的结果替换匹配的子组。如何使用Powershell做到这一点?
PowerShell版本3.0
尽管$hash
是哈希表,但以下操作无效:
$string = '<author>A12345</author>'
$string -replace '(<author>)([^<]+)', '$1$($hash[$matches[2]])'
将会输出:<author>$($hash[$matches[2]])</author>
由于有了这些评论,我现在可以使用该部分了。 我的目标是处理svn命令的输出以映射作者
svn @args | ForEach-Object -Process {
If (($_ -match "(<author>)([^<]+)") -and ($users.ContainsKey($matches[2]))) {$_ -replace '(<author>)([^<]+)', "`$1$($users[$matches[2]])"}
else {$_}}
我现在想念的是我想将此设置为IntelliJ中的新svn命令,因此需要直接调用此PowerShell脚本,或者通过批处理脚本调用该PowerShell脚本,并传递参数。目前,我正在使用批处理脚本,但由于某种原因,它无法与IntelliJ一起使用:
powershell " ""C:\tools\svnTools\selSvn.ps1 """ %*