Powershell script for copy to one html file from another

I try to make powershell script that will paste content between [] separators and paste them to another file in specified place.
Every time i use script i get:

Extracting snippet between [STYLE] and [FORM] Pattern: [STYLE](.*?)[FORM] No snippet found between [STYLE] and [FORM] 

At the end of my css file i think something can be wrong with the pattern because part of the code that paste values works fine.

# Define the file paths
$htmlFilePath = "./raport-skutecznosc-monitoringu.html"
$snippetsFilePath = "./forms/report-download-form.html"
$cssFilePath = "./css/geotiks-beautiful-site-422f61c8cadc871e.webflow.css"

# Read the HTML file content with the correct encoding
$htmlContent = Get-Content -Path $htmlFilePath -Raw -Encoding UTF8

# Read the snippets file content with the correct encoding
$snippetsContent = Get-Content -Path $snippetsFilePath -Raw -Encoding UTF8

# Read the CSS file content with the correct encoding
$cssContent = Get-Content -Path $cssFilePath -Raw -Encoding UTF8

# Function to extract snippet from the snippets content
function Get-Snippet {
    param (
        [string]$content,
        [string]$startTag,
        [string]$endTag
    )
    # Debugging output
    Write-Output "Extracting snippet between $startTag and $endTag"
    
    # Regex pattern to match content between startTag and endTag
    $pattern = [regex]::Escape($startTag) + "(.*?)" + [regex]::Escape($endTag)
    Write-Output "Pattern: $pattern"
    
    if ($content -match $pattern) {
        Write-Output "Snippet found: $($matches[1])"
        return $matches[1]
    } else {
        Write-Output "No snippet found between $startTag and $endTag"
    }
    return ""
}


# Extract snippets from the snippets content
$Headsnippet = Get-Snippet -content $snippetsContent -startTag "[HEAD]" -endTag "[STYLE]"
$stylesnippet = Get-Snippet -content $snippetsContent -startTag "[STYLE]" -endTag "[FORM]"
$formsnippet = Get-Snippet -content $snippetsContent -startTag "[FORM]" -endTag "[SCRIPT]"
$scriptsnippet = Get-Snippet -content $snippetsContent -startTag "[SCRIPT]" -endTag "[END]"

# Function to insert snippet at a specific placeholder
function Insert-Snippet {
    param (
        [string]$content,
        [string]$placeholder,
        [string]$snippet
    )
    return $content -replace [regex]::Escape($placeholder), $snippet
}

# Insert snippets at designated placeholders in HTML
$htmlContent = Insert-Snippet -content $htmlContent -placeholder "[HEAD]" -snippet $Headsnippet
$htmlContent = Insert-Snippet -content $htmlContent -placeholder "[FORM]" -snippet $formsnippet
$htmlContent = Insert-Snippet -content $htmlContent -placeholder "[SCRIPT]" -snippet $scriptsnippet

# Append the style snippet to the CSS file
$cssContent += "`n" + $stylesnippet

# Write the updated content back to the HTML and CSS files with the correct encoding
Set-Content -Path $htmlFilePath -Value $htmlContent -Encoding UTF8
Set-Content -Path $cssFilePath -Value $cssContent -Encoding UTF8

Write-Output "Snippets have been inserted successfully."