RegEx for Date

I have a large file with, roughly, 20K lines.  The lines I'm interested in start with DTP*348*D8* and then the date in yyyymmdd format.  Example: DTP*348*D8*20150601

What pattern would I use to find all of those lines where the date is prior to 20140601?

Thanks!
yukonjayAsked:
Who is Participating?

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

x
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.

NVITEnd-user supportCommented:
If you are ok with using the Windows CMD prompt and a .bat file, make a .bat file of this code.
Change the following variables to your needs:
- CompStr
- SrcFN
- IntFN
- ResultsFN

Note: ResultsFN is appended to at each run of the .bat. If you want to run it more than once, rename ResultsFN before running it.

set CompStr=20140601
set SrcFN=GiantFile.txt
set IntFN=x2.txt
set ResultsFN=xResults.txt
findstr /n /r DTP\*348\*D8\* "%SrcFN%" >"%IntFN%"
for /f "tokens=1-5* delims=*" %%a in (%IntFN%) do (
  if %%d lss %CompStr% echo %%a*%%b*%%c*%%d %%e>>"%ResultsFN%"
)
del /q "%IntFN%"

Open in new window

yukonjayAuthor Commented:
I would prefer a regex as I will be using it as part of a C# application to modify particular lines in a file.  Is there a way I can incorporate your suggestion into that solution?
Shahan AyyubSenior Software EngineerCommented:
Since you want to first find out the string and then process the date inside string. You have to do it in two steps as I see:

First find the string using regex with this pattern:
DTP\*348\*D8\*(\d{8})

Open in new window


Then using the first group of this match parse it to a date time object, probably using `DateTime.ParseExact` function. Then you have datetime object so you can compare this date with your required date and keep relevant records in `List<string>`.

If you need more on this please let me know.

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
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
Regular Expressions

From novice to tech pro — start learning today.