So I got this regex expression to work in Regex101 and it captures exactly what I want to capture. https://regex101.com/r/aJ1bZ4/3
But when I try the same thing in powershell all I get is the first set of matches. I've tried using the (?s:), the (?m:) but none of these modifiers seem to do the job. Here is my powershell script.
$reportTitleList = type ReportExecution.log | Out-String |
where {$_ -match "(?<date>\d{4}\/\d{2}\/\d{2}).*ID=(?<reportID>.*):.*Started.*Title=(?<reportName>.*)\[.*\n.*Begin ....... (?<reportHash>.*)"} |
foreach {
new-object PSObject -prop @{
Date=$matches['date']
ReportID=$matches['reportID']
ReportName=$matches['reportName']
ReportHash=$matches['reportHash']
}
}
$reportTitleList > reportTitleList.txt
What am I doing wrong? Why am I not getting all the matches as the regex101 example?
where, but your regex is a multiline regex containing\n. The regex will never see a newline character, or the "started", "begin", "end" lines at once, so it won't match properly.