SausageBuscuit
SausageBuscuit

Reputation: 1276

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:[email protected]
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:[email protected]\r\nUID:

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

Upvotes: 0

Views: 1197

Answers (2)

Lucas Trzesniewski
Lucas Trzesniewski

Reputation: 51330

Replace this pattern:

^(DTSTAMP:.+)$

With this replacement string:

\1\r\nORGANIZER;CN=Test:mailto:[email protected]

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.

Upvotes: 2

Federico Piazza
Federico Piazza

Reputation: 30985

You can use this regex:

(DTSTAMP.*)

Working demo

Check the substitution section:

enter image description here

Upvotes: 1

Related Questions