在特定行添加尾部文本

huangapple go评论43阅读模式
英文:

Adding trailing text to specific lines

问题

I need to add a trailing thxt to lines, but only to lines which begins with a specific text.

Example:

AAA First Line text
BBB Second line text

I need to add the trailing text only to lines which begins with BBB, so, supposing to add "with trailing text", the final result will be:

AAA First Line text
BBB Second line text with trailing text

Any idea about how to obtain this?

Tried with some regular expression and substitution, but I can't find a way to impose the condition that only lines beginning with something specific will get the trailing text.

英文:

I need to add a trailing thxt to lines, but only to lines which begins with a specific text.

Example:

AAA First Line text
BBB Second line text

I need to add the trailing text only to lines which begins with BBB, so, supposing to add "with trailing text", the final result will be:

AAA First Line text
BBB Second line text with trailing text

Any idea about how to obtain this?

Tried with some regular expression and substitution, but I can't find a way to impose the condition that only lines beginnig with something specific will get the trailing text

答案1

得分: 0

在Notepad++的替换对话框中,您需要点击右下角的正则表达式单选按钮。然后您可以:

  • 查找:^(BBB.*)$
  • 替换:\1 with trailing text

工作原理如下:

  • ^...$ 表示整行而不仅仅是其中的一部分
  • (...) 表示捕获此文本为\1
  • BBB.* 表示BBB后面跟着0个或多个任意字符
  • \1 表示将其替换为先前捕获的内容
英文:

In Notepad++ on the Replace dialog you need to click the Regular Expression radio button at the bottom right. Then you can:

  • Find: ^(BBB.*)$
  • Replace: \1 with trailing text

How that works is:

  • ^...$ means the entire line instead of just part of it
  • (...) means capture this text as \1
  • BBB.* means BBB followed by 0 or more of any character
  • \1 means replace this with whatever was captured earlier

huangapple
  • 本文由 发表于 2023年2月16日 06:09:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/75465891.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定