title: Match replace with regular expression and lookup table
body: <p>I want to match using regular expressions and replace a subgroup of the match using a result that I will lookup in a table using the subgroup as the key. How can I do that with powershell?</p>
  
  <p>PowerShell version <code>3.0</code></p>
  
  <p>The following doesn't work, although <code>$hash</code> is a hashtable:</p>
  
  <pre><code>$string = '&lt;author&gt;A12345&lt;/author&gt;' 
  $string -replace '(&lt;author&gt;)([^&lt;]+)', '$1$($hash[$matches[2]])'
  </code></pre>
  
  <p>Will output: <code>&lt;author&gt;$($hash[$matches[2]])&lt;/author&gt;</code></p>
  
  <p>Thanks to the comments I now got that part to work.
  My objective is to process the output of the svn command to map the authors</p>
  
  <pre><code>svn @args | ForEach-Object -Process {
  If (($_ -match "(&lt;author&gt;)([^&lt;]+)") -and ($users.ContainsKey($matches[2]))) {$_ -replace '(&lt;author&gt;)([^&lt;]+)', "`$1$($users[$matches[2]])"} 
  else {$_}} 
  </code></pre>
  
  <p>What I'm missing now is that I want to set this as the new svn command in IntelliJ, therefore this PowerShell script needs either to be called directly or be called through a batch script and the arguments passed through. At the moment I'm using a batch script but for some reason it is not working with IntelliJ:</p>
  
  <pre><code>powershell " ""C:\tools\svnTools\selSvn.ps1 """ %*
  </code></pre>