I have this PowerShell script, the main purpose of which is to search through HTML files in a folder, search for specific HTML markup and replace it with what I tell him.
I was able to make 3/4 of my find and replaced perfectly. I am having problems with regex.
This is the markup in which I am trying to find and replace my regex:
<a href="programsactivities_skating.html"><br /> </a>
Here is the regex that I still have, along with the function that I use in it:
automate -school "C:\Users\$env:username\Desktop\schools\$question" -query '(?mis)(?!exclude1|exclude2|exclude3)(<a[^>]*?>(\s| |<br\s?/?>)*</a>)' -replace ''
And here is the automation function:
function automate($school, $query, $replace) { $processFiles = Get-ChildItem -Exclude *.bak -Include "*.html", "*.HTML", "*.htm", "*.HTM" -Recurse -Path $school foreach ($file in $processFiles) { $text = Get-Content $file $text = $text -replace $query, $replace $text | Out-File $file -Force -Encoding utf8 } }
I have been trying to find a solution for this for about 2 days, and just can't get it to work. I decided that the problem is that I need to tell my regular expression about the Multiline account and what I'm having problems with.
Any help anyone can provide is greatly appreciated.
Thanks at Advance.
regex powershell
Matt bettiol
source share