0

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.

PiEnthusiast
  • 314
  • 1
  • 4
  • 19

2 Answers2

0

I guess newlines are removed or ignored, because your regex does not care about them.

I only have a correction to the match after CATEGORIES

BEGIN:VEVENT.+?CATEGORIES:Sports.*?END:VEVENT
                                 ^
                               Zero or more

The first part of your regex looks good, maybe the regex engine in EditPad is not so good. Try it with a different editor or scripting language (like Eclipse or perl or Notepad+ or Notepad2)

You could split the input and then grep the matching Sports events

@sportevents = grep /Sports/, split /END:VEVENT/, $input
map $_.="END:VEVENT", @sportevents

This was perl, maybe you can launch a script from EditPad to do it.
The second line just restores the END:VEVENT that was stripped during split.

ilomambo
  • 8,290
  • 12
  • 57
  • 106
  • Thanks for the feedback and thanks for pointing out the typo. I actually switched from Notepad++ to EditPad because of the better regex engine. Nevertheless, the result is the same in both. – PiEnthusiast Feb 13 '13 at 16:49
  • Thanks for the perl idea, I'll give it a spin on my raspberry. If I knew more perl I would probably loop through all possible categories but I am lacking [skills and time](http://xkcd.com/974/). – PiEnthusiast Feb 14 '13 at 07:04
0

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.

PiEnthusiast
  • 314
  • 1
  • 4
  • 19