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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Question answered.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.