title: Extracting data from the $matches hashtable after a Powershell Regeg -match
body: <p>I've already spent over an hour trying to get a simple RegEx to work.  My pattern is working, and I'm getting back the $Matches which as I have read is supposed to be a hash table.  So how do I get what I've captured? </p>
  
  <p>Code:  </p>
  
  <pre><code>   cls 
     $keyword = "this is a 12345 test" 
     $pattern = "\d{5}"
     $keyword -match $pattern 
     $returnZipcode = "ERROR" 
     Write-Host "GetZipCodeFromKeyword RegEx `$Matches.Count=$($Matches.Count)" 
     $Matches | Out-String | Write-Host
     Write-Host "`$Matches[0].Value=$($Matches[0].Value)"
     Write-Host "`$Matches.Get_Item('0')=$($Matches.Get_Item("0"))"
     if ($Matches.Count -gt 0) 
        {
           $returnZipcode = $Matches[0].Value
        }
  
     # this is how hash tables work - why doesn't same work with the $Matches variable? 
     $states = @{"Washington" = "Olympia"; "Oregon" = "Salem"; California = "Sacramento"}
     $states | Out-String | Write-Host
     Write-Host "`$states.Get_Item('Oregon')=$($states.Get_Item("Oregon"))"
  </code></pre>
  
  <p>Run time results: </p>
  
  <pre><code>Name                           Value  
  ----                           -----  
  0                              12345  
  
  $Matches[0].Value=
  $Matches.Get_Item('0')=
  
  Name                           Value
  ----                           -----
  Washington                     Olympia
  Oregon                         Salem  
  California                     Sacramento 
  
  $states.Get_Item('Oregon')=Salem
  </code></pre>