【问题标题】:Add text to beginning of line if a string is present in that line如果该行中存在字符串,则将文本添加到行首
【发布时间】:2017-11-22 09:50:41
【问题描述】:

我正在使用 Notepad++ 并处理大约 400MB 的巨大日志文件。如果特定行中存在某个字符串,是否可以将特定文本放在行首? 例如:

输入

This is a sentence
This is a sentence
This is the sentence
This is a sentence

我希望在带有单词“the”的行前面添加文本 YES

输出

 This is a sentence
 This is a sentence
 YES This is the sentence
 This is a sentence

【问题讨论】:

  • 我不知道是否使用编辑器,但如果使用编程语言,它只是使用循环和 strpos

标签: string text notepad++


【解决方案1】:

您可以尝试以下查找和替换:

查找:

(.*\bTHE_STRING\b.*)

替换:

SOME_TEXT$1

查找模式将匹配并消耗整行,但前提是应该出现感兴趣的字符串。然后,对于替换,我们使用您的新文本,然后是整个原始行。

【讨论】:

    猜你喜欢
    • 2017-10-08
    • 2022-08-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-13
    • 1970-01-01
    相关资源
    最近更新 更多