Notepad ++将字符串添加到特定行

时间:2018-10-12 14:41:03

标签: windows notepad++ line

有什么方法可以在Notepad ++中将字符串添加到特定行的开头吗?

例如,我想向第23行添加一个字符串,然后转到新行。有可能吗?

编辑:

输入:

text 1
text 2
text 3

预期结果:

text 1
text 2
ADDED LINE
text 3

我知道我可以在其中复制并粘贴字符串,但是我必须对多个文件执行此操作。

1 个答案:

答案 0 :(得分:0)

  • Ctrl + H
  • 查找内容:^(?:.+(\R)){23}
  • 替换为:$0added line$1
  • 检查正则表达式
  • 请勿检查. matches newline
  • 确保将光标放置在第一行的开头,然后
  • 替换

说明:

^           : beginning of line
  (?:       : start non capture group
    .+      : 1 or more any character but newline
    (\R)    : group 1, any kind of linebreak (ie. \r, \n, \r\n)
  ){23}     : non capture group must appears 23 times

替换:

$0          : the whole match
added line  : line to be added
$1          : content of group 1 (i.e. linebreak)