Find and replace strings with REGEX and replacement string is incremental

Hello, I have a big file with several patterns to be replaced. Some of the strings are on the same line and I also need to increment the replacement value. At last I would like to keep in a file the “matching/original” value and “replaced” value. Any ideas how to achieve that?

Example input:


<requestId>qwerty-qwer12-qwer56</requestId>Ace of Base Order: Q2we45-Uj87f6-gh65De<something else...
<requestId>zxcvbn-zxcv4d-zxcv56</requestId>
<requestId>1234qw-12qw9x-123456</requestId> Stevie Wonder <messageId>1234qw-12qw9x-123456</msg

Desired output:

<requestId>Request-1</requestId>Ace of Base Order: Request-2<something else...
<requestId>Request-3</requestId>
<requestId>Request-4</requestId> Stevie Wonder <messageId>Request-4</msg

And the code which I cannot make running is:

@’
<requestId>qwerty-qwer12-qwer56</requestId>Ace of Base Order: Q2we45-Uj87f6-gh65De<something else…
<requestId>zxcvbn-zxcv12-zxcv56</requestId>reportId>poGd56Hnm9q3Dfer6Jh</msg:reportId>
<requestId>1234qw-12qw12-123456</requestId>kljsldjslddsdfdsdsdfff <messageId>1234qw-12qw12-123456</msg
reportId>plmkjh8765FGH4rt6As</msg:reportId>

'@ | Set-Content $log -Encoding UTF8

$requestId = @{
Count = 1
Matches = @()
}

$repid= [regex]::matches((Get-Content $log),‘\w{6}-\w{6}-\w{6}’).value
foreach( $rep in $repid ) {
$matched = @($_ | Select-String -Pattern $rep)
if( -not $matched ) {
return
}
$_
}
Get-Content $log