$Matches

noun

say it: “DOL-er MACH-iz” /ˈdɑlər ˈmætʃɪz/

A PowerShell variable that holds the text the last successful -match found.

What is $Matches?

$Matches holds what the last -match that answered True found: $Matches[0] is the whole text the pattern matched. PowerShell fills it for you after every successful -match, so read it right after the test.

'paid order TM-48213' -match '\d+'
$Matches[0]    # 48213

In a sentence

  • “Diego read $Matches right after the test, before running another -match.”
  • “$Matches[0] held TM-48213, the order number the pattern found.”

Level: Apprentice · More PowerShell terms at this level

Updated