I have this test data:
^Test data
This is all just test data
testing 123
ABC>space "ABC"
ABC>
And I've setup a regex on regex101.com
(^\^|ERROR).*((|\n|\r|\w|\W)?)+(?=ABC>)
The expression is returning just what I want on the site:
I am using this powershell I wrote to get content similar to the content above and looping through files, and looking for matches of the same regex expression.
$files = gci "\\server\path"
$content = @()
ForEach($file in $files){
# Set script name
$scriptname = "ABC TEST_081722"
# Get the name of the task for the logfile's filename.
$taskname = "THIS IS A TEST!!!"
# Create log file with a datestamp MMDDYY
$datestamp = (get-date).ToString('MMddyy')
$logfilepath = "\\server\path\Logs\$($taskname)\$($file.basename).log"
$log_dir = "\\server\path\Logs\$($taskname)\"
# Get the content of the log file. We are only interested in getting lines which match a regex for our command line and our output line.
$content_raw = get-content $logfilepath -raw
$content_raw -match "(^\^|ERROR).*((|\n|\r|\w|\W)?)+(?=ABC>)"
Write-host -f yellow $file.fullname
$matches
$matches.clear()
start-sleep -s 2
}
The regex finds a match in two of my three test files, but not the first one which has the exact same string content as my example above. Why does it find a match in the 2nd and 3rd file but not the first?
The content of the 2nd and 3rd file are like so
ABC>W !,MSG
ERROR^BATCH~Batch in use
ABC>space "ABC"
So these two files do not have a line starting with a "^" symbol. It starts with "ERROR" which I accounted for with my OR statement in my regex. I just don't understand how it is able to find the lines which start with "ERROR" find, but not finding the lines from the first file which starts with "^" carat.
