我有一个文本文件充满了以下行:
F randomtext F morerandomtext
字符串我需要什么类型的正则表达式,这样输出就像这样:
randomtext,foo morerandomtext,foo
型所以F变成了foo,并移到了行尾。
svdrlsy41#
查找:
F (.*)
字符串全部替换为:
\1,foo
型
z18hc3ub2#
我想补充一点:使用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
字符串
kzmpq1sx3#
使用你所展示的示例,请在你的notepad++文件中尝试下面的正则表达式。
^\S+\s(.*)$
^\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.
3条答案
按热度按时间svdrlsy41#
查找:
字符串
全部替换为:
型
z18hc3ub2#
我想补充一点:使用Notepad++,您也可以使用正则表达式查找和替换一组文件中的内容。下面将查找所有以大写F开头的行和D中的空格的文件:\mydir -文件夹的 *.txt文件,包括子目录。
要打开Notepad++中的“在文件中查找”窗口,请键入Ctrl+Shift+F。
字符串
kzmpq1sx3#
使用你所展示的示例,请在你的notepad++文件中尝试下面的正则表达式。
^\S+\s(.*)$
***替换为:***
\1,foo
字符串