JustPaste.it

hello. I have this 2 comments tag from different 2 files, from Folder1 and Folder 2. 

 

<!--STARTDATES-->
<td class="text_dreapta">On April 07, 2009, in <a href="https://justpaste.it/redirect/3itif/https%3A%2F%2Fmywebsite.com%2Fen%2Flink.html" title="View all articles from Link" class="external" rel="nofollow">Link</a>, by Roger Moore</td>
<!--FINNISHDATES-->

and

<!--STARTDATES-->
<a href='' class="color-black">On April 07, 2009, in</a>
<a href="https://justpaste.it/redirect/3itif/https%3A%2F%2Fmywebsite.com%2Fen%2Flink.html" title="View all articles from Link" class="color-green font-weight-600 mx-1">Link</a>
<a href='' class="color-black mr-2">by Roger Moore</a>
<!--FINNISHDATES-->

 


I want to copy/parsing some information from the first html comment to the second html comment. I believe the code in PowerShell is good, I use a regex to select some tags from the first comment and another regex to replace the tags on the second comment. 

 

THE PROBLEM is that I must also to select the location where the regex should work, meaning between <!--STARTDATES--> and<!--FINNISHDATES-->. Otherwise the regex can also select other tags with the same name from the same file.

 

So, I have to restrict running this PowerShell code only in the perimeter <!--STARTDATES--> and <!--FINNISHDATES--> I believe I must add some lines, with this 2 parametres, but I don't know how to do this. Can anyone help me?


$sourceFiles = Get-ChildItem 'c:\Folder1'
$destinationFolder = 'c:\Folder2'

foreach ($file in $sourceFiles) {

$sourceContent = Get-Content $file.FullName -Raw
$contentToInsert = [regex]::match($sourceContent,"(?ms)<td class="text_dreapta">(.+)</td>").value
$destinationContent = Get-Content $destinationFolder\$($file.Name) -Raw
$destinationContent = $destinationContent -replace '(?ms)<td class="color-black">(.+)</a>',$contentToInsert

Set-Content -Path $destinationFolder\$($file.Name) -Value $destinationContent -Encoding UTF8

} #end foreach file