Q:

Notepad++ Regex to Insert Line between certain lines

I was trying this in Notepad++, but I'm not entirely sure if it's possible there.  I have an iCal file where I need to insert some missing "Organizer" fields.  For example, I need
DTSTAMP:20140821T160519Z
UID:ExampleUID1

to be this
DTSTAMP:20140821T160519Z
ORGANIZER;CN=Test:mailto:me@example.com
UID:ExampleUID1

The organizer is there in some cases, and is not a static value.  How can I do this while keeping the DTSTAMP string intact?  Finding DTSTAMP:[A-Za-z0-9_]*$\r\nUID: finds the entries, but I can't find out what to replace with. Using
DTSTAMP:^([A-Za-z0-9_])*$\r\nORGANIZER;CN=Test:mailto:me@example.com\r\nUID:

or any variation thereof injects the actual regex text (^[A-Za-z0-9_]*$.) into the results.

A:

Replace this pattern:
^(DTSTAMP:.+)$

With this replacement string:
\1\r\nORGANIZER;CN=Test:mailto:me@example.com

You have to check the Regular expression mode (obviously), and uncheck the . matches newline option.
For some additional security, you also cound use this pattern:
^(DTSTAMP:.+)$(?!\r\nORGANIZER)

This won't insert an ORGANIZER field if one already exists just below the DTSTAMP field.
Also, if your iCal file is in UNIX newline format, replace every \r\n with \n.

