简体   繁体   English

Notepad ++正则表达式可在某些行之间插入行

[英]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. 我曾在Notepad ++中尝试过此方法,但不确定是否可以在其中进行完全确定。 I have an iCal file where I need to insert some missing "Organizer" fields. 我有一个iCal文件,我需要在其中插入一些缺少的“整理器”字段。 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? 如何在保持DTSTAMP字符串完好无损的情况下执行此操作? Finding DTSTAMP:[A-Za-z0-9_]*$\\r\\nUID: finds the entries, but I can't find out what to replace with. 查找DTSTAMP:[A-Za-z0-9 _] * $ \\ r \\ nUID:查找条目,但是我找不到替换的条目。 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-Za-z0-9 _] * $。)注入结果中。

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. 如果DTSTAMP字段正下方已经存在一个ORGANIZER字段,则不会插入该字段。

Also, if your iCal file is in UNIX newline format, replace every \\r\\n with \\n . 另外,如果您的iCal文件为UNIX换行符格式,请用\\r\\n替换每个\\r\\n \\n

You can use this regex: 您可以使用此正则表达式:

(DTSTAMP.*)

Working demo 工作演示

Check the substitution section: 检查替换部分:

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM