Notepad++正则表达式替换

30
我有一个文本文件,里面充满了以下内容的行:
F randomtext
F morerandomtext

我需要什么样的正则表达式才能得到这样的输出结果:
randomtext,foo
morerandomtext,foo

所以F变成了foo并移到了行尾。
3个回答

73

查找:

F (.*)

将所有内容替换为:

\1,foo

4
我想补充一下:使用Notepad++,您可以使用正则表达式查找和替换一组文件中的内容。下面的代码将查找所有以大写字母F和空格开头的行的文件,包括子目录中D:\mydir文件夹中的*.txt文件。
要在Notepad++中打开“查找文件”窗口,请键入Ctrl + Shift + F。
Find what: ^F (.*) 
Replace with: \1,foo
Filters: \1,foo
Directory: D:\mydir
Match case: Checked
In all sub-folders: Checked
Search Mode: Regular expression

1
请在您的Notepad++文件中尝试以下正则表达式,根据您所展示的示例。
查找内容: `^\S+\s(.*)$`

Replace with: \1,foo

Explanation of regex:

^\S+    ##Match from starting 1 or more occurrences of non-spaces here.
\s      ##Matching space here.
(.*)$   ##Creating one and only Capturing group which contains everything till the end of the value.


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接