我有三个文件,main.txt
,out.txt
和in.txt
. 我想用 的内容替换每次出现的out.txt
inmain.txt
内容in.txt
。
和out.txt
都in.txt
可以包含多行和各种特殊字符。如何正确读取和转义这些字符串?
这是一个包含一些边缘情况的示例,例如特殊字符、重复匹配、不完整匹配、重叠匹配。
main.txt
:
foo
Replace these
three lines
with some $.*\'"& in it
bar
Replace these
three lines
with some $.*\'"& in it
Replace these
three lines
with some $.*\'"& in it
three lines
Replace these
three lines
three lines
with some $.*\'"& in it
baz
Run Code Online (Sandbox Code Playgroud)
out.txt
:
Replace these
three lines
with some $.*\'"& in it
Run Code Online (Sandbox Code Playgroud)
in.txt
:
Replacement …
Run Code Online (Sandbox Code Playgroud)