How to make a parsing only in some html comment tag / in some particular htm tag

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

On April 07, 2009, in Link, by Roger Moore


On April 07, 2009, in
by Roger Moore


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)(.+)").value
$destinationContent = Get-Content $destinationFolder\$($file.Name) -Raw
$destinationContent = $destinationContent -replace '(?ms)class="color-black">(.+)',$contentToInsert

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

} #end foreach file


You can also see the code of this topic here: - Share Text & Images the Easy Way