The issue is that each pipeline expression is a closure.
Where-Object
is only going to send the Item that matched down the pipeline, not the context.
The simplest to understand method is to do:
Get-Collection | ForEach-Object { if($_.Name -match $regex) { [int] $Matches[1] } }