Select-String -Pattern returns the location of each match. For example:
$s = 'abcxyzabc' | Select-String -Pattern 'abc(?<x>.*)abc'
$s.Matches[0].Groups | Select-Object Name, Value, Index, Length
gives:
Name Value Index Length
---- ----- ----- ------
0 abcxyzabc 0 9
x xyz 3 3
where Index and Length specifies the location of each match.
However, I can't find how to get the location of each match when using switch -regex. For example:
switch -regex ('abcxyzabc') {
'abc(?<x>.*)abc' {
$matches
}
}
gives:
Name Value
---- -----
x xyz
0 abcxyzabc
I can't find anything like Index and Length to get the match location in $matches.
I also checked that the type of Matches returned by Select-String -Pattern is System.Text.RegularExpressions.Match[], while the type of $matches in switch -regex is System.Collections.Hashtable.
Did I miss anything or switch -regex is not supposed to give the location of each match?