hello. I have more regex to run on multiple html files from Folder1. I must run more REGEX with search and replace, for example:
SEARCH: (?-s)(".+?")
REPLACE BY: $0
SEARCH: (^.*?)=(.*$)
Replace by: \1\r\n\2
SEARCH: ^.(.*)$
REPLACE BY: \1
I mage a PowerShellp script, I add those 3 regex search and replace formulas, but is not working. Can anyone help me?
$sourceFiles = Get-ChildItem 'c:\Folder1'
$destinationFolder = 'c:\Folder1'
foreach ($file in $sourceFiles) {
$sourceContent = Get-Content $file.FullName -Raw
$contentToInsert = [regex]::match($sourceContent,"(?-s)(".+?")").value
$destinationContent = Get-Content $destinationFolder\$($file.Name) -Raw
$destinationContent = $destinationContent -replace '$0',$contentToInsert
$contentToInsert = [regex]::match($sourceContent,"(^.*?)=(.*$)").value
$destinationContent = Get-Content $destinationFolder\$($file.Name) -Raw
$destinationContent = $destinationContent -replace '\1\r\n\2',$contentToInsert
$contentToInsert = [regex]::match($sourceContent,"^.(.*)$").value
$destinationContent = Get-Content $destinationFolder\$($file.Name) -Raw
$destinationContent = $destinationContent -replace '\1',$contentToInsert
Set-Content -Path $destinationFolder\$($file.Name) -Value $destinationContent -Encoding UTF8
} #end foreach file