Search code examples
regexwindowsicalendarnon-greedyeditpad

Using regex to eliminate chunks in a file (categorized events in iCal file)


I have one .ics file from which I would like to create individual new .ics files depending on the event categories (I can't get egroupware to export only events of one category, I want to create new calendars depending on category). My intended approach is to repeatedly eliminate all events but those of one category and then save the file using EditPad Lite 7 (Windows).

I am struggling to get the regular expression right. .+? is still too greedy and negating the string (e.g. to eliminate all but events from one category) doesn't work either.

Sample

    BEGIN:VEVENT
    DESCRIPTION:Event 2
    END:VEVENT
    BEGIN:VEVENT
    DESCRIPTION:Event 3
    CATEGORIES:Sports
    END:VEVENT
    BEGIN:VEVENT
    DESCRIPTION:Event 4
    END:VEVENT

The regex BEGIN:VEVENT.+?CATEGORIES:Sports.+?END:VEVENT should only match sports events but it catches everything from the first BEGINto the first ENDfollowing the category.

Edit: negating doesn't work either: BEGIN:VEVENT.+?((?!CATEGORIES:Sports).).+?END:VEVENT.

What am I missing? Any pointers are highly appreciated.


Solution

  • OK. Solved it. I found something here which can be used to split ics files. I tweaked it to use the category rather than the summary in the file name and then merged the individually generated files according to category. I added the usual ics header and footer to all files and, voilà, I had individual calendar files.