Capture matched portions in the $matches variable
The first element of this array stores the entire match, the subsequent elements the individual parts that were captured with parentheses:
'First number: 42, second number: 99, third number 18.' -match '(\d+)\D+(\d+)\D+(\d+)'
#
# True
# Print entire matching string:
$matches[0]
#
# 42, second number: 99, third number 18
# First, second and third number:
$matches[1]
#
# 42
$matches[2]
#
# 99
$matches[3]
#
# 18
For easier reading, it's also possible to capture a matched portion of the text with name-tag. This requires the capturing parenthesis to look look like so:
(?<NAME>REGEXP)
.
NAME
then becomes the key in the
$matches
hash table:
'First number: 42, second number: 99, third number 18.' -match '(?<first>\d+)\D+(?<second>\d+)\D+(?<third>\d+)'
#
# True
# Print entire matching string:
$matches[0]
#
# 42, second number: 99, third number 18
# First, second and third number:
$matches['first']
#
# 42
$matches['second']
#
# 99
$matches['third']
#
# 18