2
저는 이미 간단한 RegEx를 작동 시키려고 1 시간 이상을 보냈습니다. 내 패턴이 작동하고, 내가 읽었던 $ Hatch를 해시 테이블로 가정한다. 그러면 내가 어떻게 잡았는지 알 수 있을까요?
코드 :
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"))"
실행 시간 결과 :
Name Value
---- -----
0 12345
$Matches[0].Value=
$Matches.Get_Item('0')=
Name Value
---- -----
Washington Olympia
Oregon Salem
California Sacramento
$states.Get_Item('Oregon')=Salem
감사합니다. 게시 된 후속 조치 : http://stackoverflow.com/questions/27194148/powershell-match-in-function-gets-extra-true-false-when-returned 나는 참/거짓이 해시 테이블의 일부로 되돌아 왔지만 여전히 확실하지 않습니다. – NealWalters