【问题标题】:How do I use notepad++ to add text to the beginning of a specific line (e.g. line 3) in multiple files?如何使用 notepad++ 将文本添加到多个文件中特定行(例如第 3 行)的开头?
【发布时间】:2014-07-14 09:06:50
【问题描述】:

使用 Notepad++,如何在多个文件的特定行(例如第 3 行)的开头添加文本?​​

考虑以下文件结构:

File1:
this.is.the.first.key=blah
me.is.second=blahblah
blahblahblah
i.is.fourth=blahblahblahblah
j=sok
i=oakfoasskf
o=sdofkogdk
this is missing a variable

这种结构存在于多个文件中,每个文件都包含相同的键(或缺少键),而值根据文件名进行翻译(一个文件是 _en,另一个是 _de 等)我想为所有行添加键错过了他们

(我看到很多建议使用 RegEx 选择行开头的答案,但没有选择特定行)。

【问题讨论】:

    标签: regex notepad++


    【解决方案1】:

    在记事本++中

    查找内容:^([^=]*)(?!=)$

    替换为:KEY=$1

    打开所有要替换的文件,然后单击“替换”选项卡下的“全部替换所有打开的文档”按钮。


    这里也是DEMO

    上述正则表达式模式查找所有没有= 符号的行。

    模式说明:

      ^                        the beginning of the string
      (                        group and capture to \1:
        [^=]*                    any character except: '=' (0 or more times)
      )                        end of \1
    
      (?!                      look ahead to see if there is not:
        =                        '='
      )                        end of look-ahead
      $                        before an optional \n, and the end of the string
    

    【讨论】:

    • 抱歉误导,var 数字实际上并不共享任何公分母(var 仅用作示例)。我编辑了我的问题,希望现在更清楚
    • 找到很棒的东西,替换的不多。我需要每个键都是不同的(例如 key1、key2、key3),因为稍后我需要从键中获取值。这有可能以某种方式实现吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-11
    • 1970-01-01
    • 1970-01-01
    • 2018-02-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多