Why do I get the extract "True" or "False" (when all I want to get back is just the zip code) on the result of this function:
Function GetZipCodeFromKeyword([String] $keyword)
{
$pattern = "\d{5}"
$keyword -match $pattern
$returnZipcode = "ERROR"
#Write-Host "GetZipCodeFromKeyword RegEx `$Matches.Count=$($Matches.Count)"
if ($Matches.Count -gt 0)
{
$returnZipcode = $Matches[0]
}
Write-Host "`$returnZipcode=$returnZipcode"
return $returnZipcode
}
cls
$testKeyword = "Somewhere in 77562 Texas "
$zipcode = GetZipCodeFromKeyword $testKeyword
Write-Host "Zip='$zipcode' from keyword=$testKeyword"
Write-Host " "
$testKeyword = "Somewhere in Dallas Texas "
$zipcode = GetZipCodeFromKeyword $testKeyword
Write-Host "Zip='$zipcode' from keyword=$testKeyword"
Results of run time:
$returnZipcode=77562
Zip='True 77562' from keyword=Somewhere in 77562 Texas
$returnZipcode=12345
Zip='False 12345' from keyword=Somewhere in Dallas Texas