Search notes:

PowerShell: the automatic variable $matches

$matches is a collection that is populated when using regular expressions with the -match and -notmatch (regexp) operator.
The type of $matches is System.Collections.Hashtable.

Simple example

'Foo 42 bar 99 baz' -match '\d+' | out-null
write-host "The matched number is $($matches[0])."
#
#  The matched number is 42. 

'Check 999 too' -notmatch '\d+' | out-null
write-host "The matched number is $($matches[0])."
#
#  The matched number is 999.
Github repository about-PowerShell, path: /language/variable/automatic/matches/simple.ps1
Note: this example does not set $matches[1].

See also

Other automatic variables

Index