Positive Lookahead

I file a file that updates whenever a file is uploaded to a particular server. I need a positive lookhead whenever whenever the pattern reaches the word "Archived".  Here is the string I use for a pattern:

Downloaded Files: 02-01-2018 09:22:30
Successful Download: 180125.65.BMT.zip
Successful Download: 180128BMT.zip
Uploaded Files on SFTP Server: 02-01-2018 09:22:30
Successful Upload: B10.DAT
Successful Upload: B9.DAT
Archived Files on Server: 02-01-2018 09:22:30
Successful Archived: Q9535.BMT.zip
Successful Archived: Q9800.BMT.zip
Downloaded Files: 02-02-2018 02:00:03

I created the following pattern:

$patter = "Uploaded Files on SmartTelecom SFTP Server:  "+ (get-date).toString("MM-dd-yyyy")

Which will pull today's date. I just need a way to copy everything (including new lines) up until "Archived"

Mario PichardoAsked:
Who is Participating?
oBdAConnect With a Mentor Commented:
You'll need to get file content using -Raw, and the inline option "s" (single line mode), so that matches will stretch over several lines.
Your current pattern does not match the sample you posted, so you will have to adjust at least $startText.
$startText and $endText are meant to hold plain text, that's why the "[regex]::Escape(...)".
$log = Get-Content -Path -Raw .\log.txt
$startText = [regex]::Escape("Uploaded Files on SFTP Server: $((Get-Date '2018-02-01').ToString('MM-dd-yyyy'))")
$endText = [regex]::Escape("Archived Files")
If ($log -match "(?s)(?<Content>$($startText).*?$($endText).*?\r\n)") {
} Else {
	"Expected text not found!" | Write-Warning

Open in new window

Question answered.
All Courses

From novice to tech pro — start learning today.