I am trying to understand the output & error message for:
# declare empty array
$thisDataArray = @()
# assign array values
$thisDataArray = '123','cadabra','456','789','trouble'
# declare empty array to receive specific values
$letters = @()
# use this pattern to filter array members that contain letters
$regex = "[a-z]"
# confirm the array values
Write-Host $thisDataArray
# pipe array & filter to find the values
$thisDataArray | Select-String -AllMatches -Pattern $regex -CaseSensitive | ForEach-Object { $letters = $_.Matches.Value}
# output the result
Write-Host $letters
The error is: The variable $letters is assigned but never used. And the output is:
123 cadabra 456 789 trouble
t r o u b l e
My questions are:
- How is
Write-Host $lettersnot using the assigned variable$letters? - Why do I only get the one array member 'trouble' from my
$regex? - And finally. Why are there spaces between the chars of trouble e.g 't r o u b l e'
Any suggestions appreciated.
