【发布时间】:2017-10-17 20:09:43
【问题描述】:
我在文件中有以下内容:
This is line one
This is line two with string1 and string3
This is line three with string3
如果该行包含“string3”,我需要将“string1”替换为“string2”,这样结果将是:
This is line one
This is line two with string2 and string3
This is line three with string3
【问题讨论】:
-
@wiktor stribizew,这不是“正则表达式:删除包含的行”的重复项。我不想删除行。
-
@WiktorStribiżew 方法可能是,但如果有人试图找到解决我面临的问题的方法,他们将不会搜索“删除包含的行”。
-
好的,那你的问题是什么?你被困在哪里了?此外,您还没有解释
string3可能出现的位置。从您的示例来看,string3似乎应该遵循`string2,是这样吗? -
@WiktorStribiżew:我同意海星的观点,这不是现有问题的完全重复...
-
@Starfish:试试这个,它在记事本++上对我有用:regex101.com/r/4L5Wyx/1