有人知道如何每 10 行添加 3 个不同的文本吗?我的意思是,如果我有 3 个文本,例如评论 1、评论 2、评论 3
我需要将 1000 行分成 30 行,在前 10 行之后我需要添加注释 1,在 20 行之后我想添加注释 2,在 30 行之后我想添加注释 3,然后我需要在所有 1000 行中重复相同的操作。有没有代码可以让我在 Notepad++ 中做到这一点??
答案1
这是完成这项工作的一种方法。
笔记:我已经做了一个例子,在两行后添加了3条不同的注释,对于你的情况,你必须更改{2}
with {10}
。
- Ctrl+H
- 找什么:
(?:\A|\G)((?:^.+\R){2})((?:^.+\R){2})?((?:^.+\R){2})?
- 用。。。来代替:
$1comment1\n(?2$2comment2\n)(?3$3comment3\n)
- 查看 环绕
- 查看 正则表达式
- 取消选中
. matches newline
- Replace all
解释:
(?:\A|\G) # non capture group, beginning of file or restart from last match position
( # group 1
(?:^.+\R){2} # non capture group, a whole line, must appear twice (in your case, change that 2 with 10)
) # end group 1
( # group 2
(?:^.+\R){2} # non capture group, a whole line, must appear twice (in your case, change that 2 with 10)
)? # end group 2, optional
( # group 3
(?:^.+\R){2} # non capture group, a whole line, must appear twice (in your case, change that 2 with 10)
)? # end group 3, optional
替代品:
$1 # content of group 1
comment1 # comment 1
\n # linefeed, you may use \r\n for windows end of line
(?2 # conditional, if group 2 exists
$2 # content of group 2
comment2 # comment 2
\n # linefeed
) # end conditional
(?3 # conditional, if group 3 exists
$3 # content of group 3
comment3 # comment 3
\n # linefeed
) # end conditional
屏幕截图(之前):
屏幕截图(之后):