Very short version of this question is "How do I remove all lines of a multiline string if they don't contain one of many keywords in the line?"
i'm making an app in php and js and really don't want to use many outside libraries to bloat my code and file structure also I'm not a huge fan of classes and methods (probably a bit of OCD on my part).
This code doesn't use the google API rather it uses the ics file because I wanted to make it more versatile
Long story short, I'm parsing an ics file to compare possible dates/times a client might book a meeting with a google calendar ics file. The goal is that I only offer meeting times that don't conflict with my schedule and that's working well so far. I have a good javascript parser I made to get the start and end times.
The issue is I'm sending my entire calendar to the client in the source code that's 10 years of events which makes the source code like 15k lines. I'm also not crazy about strangers having access to that much detail with my schedule and private info. I'd like a php script to remove the lines that don't start with DTSTART or DTEND but when I see a pregreplace I glaze over I have a hard time understanding it. I use them but I have a hard time with them.
What's the pregreplace to keep the entire line of an ics if it starts with "DTSTART" or "DTEND" and remove everything else?
There are probably a few other lines I'll have to add to keep my javascript ics parser from breaking too. But I really want to solve the privacy issue. In a perfect world I'd also get rid of events that have already ended while I'm parsing because they can't conflict with future events.
Here is a chunk of text from the ics file I've redacted some trivial private info just in case
BEGIN:VEVENT
DTSTART:20200907T170000Z
DTEND:20200907T180000Z
DTSTAMP:20221231T224008Z
UID:(redacted)
CREATED:20200820T161956Z
DESCRIPTION:
LAST-MODIFIED:20200820T162009Z
LOCATION:
SEQUENCE:1
STATUS:CONFIRMED
SUMMARY:Contact (redacted name here)
TRANSP:OPAQUE
END:VEVENT
BEGIN:VEVENT
DTSTART;VALUE=DATE:20201101
DTEND;VALUE=DATE:20201104
DTSTAMP:20221231T224008Z
UID:(redacted)
CREATED:20200818T153428Z
DESCRIPTION:
LAST-MODIFIED:20200818T153428Z
LOCATION:
SEQUENCE:0
STATUS:CONFIRMED
SUMMARY:..REDACTED PRIVATE INFO
TRANSP:TRANSPARENT
BEGIN:VALARM
ACTION:DISPLAY
DESCRIPTION:This is an event reminder
TRIGGER:-P0DT4H0M0S
END:VALARM
END:VEVENT
BEGIN:VEVENT
From this chunk I'd like to only keep lines like these (or ideally ones with DTEND:2023 and up):
BEGIN:VEVENT
DTSTART:20200907T170000Z
DTEND:20200907T180000Z
END:VEVENT
BEGIN:VEVENT
DTSTART;VALUE=DATE:20201101
DTEND;VALUE=DATE:20201104
END:VEVENT
BEGIN:VEVENT...