在Word Vs之前每次更改字符后添加一个空行

时间:2017-07-06 07:33:00

标签: regex notepad++

使用TextFx工具我删除重复的行 问题:想要对“Vs”之前的部分相同的行进行分组。 我想在更改后添加一个空行。

示例

之前的行:

- traveling by plane Vs By TGV train.
- travel by plane Vs By TGV train.
- traveling by Bike Vs By Cycle.
- travel With plane Vs By TGV train.
- traveling by Bike Vs By TGV train.
- traveling by Bike Vs By Cycle.
- traveling by Bike Vs By TGV.
- traveling by Car Vs By TGV train.
- traveling by Car Vs By Truck.
- traveling by Car Vs By Bike.
- traveling by Car Vs By TGV.

后面的行:

- traveling by plane Vs By TGV train.

- travel by plane Vs By TGV train.

- travel With plane Vs By TGV train.

- traveling by Bike Vs By TGV train.
- traveling by Bike Vs By TGV.
- traveling by Bike Vs By Cycle.

- traveling by Car Vs By TGV train.
- traveling by Car Vs By TGV.
- traveling by Car Vs By Truck.
- traveling by Car Vs By Bike.

1 个答案:

答案 0 :(得分:0)

我想这就是你所追求的 - 替换

^(.*?)\bVs\b(?!.*\s+\1).*

$0\n

正则表达式首先匹配行^的开头,然后将单词Vs的所有内容捕获到组2中。匹配单词后,它使用负面预测确保下一行的开头与此行的开头不同(将任何内容与.*的行尾匹配,将新行与\s+匹配,然后使用对所捕获的开头的反向引用这条线)。如果这个负面前瞻匹配(下一行当前的方式启动),我们有一个匹配,用于在当前后插入一个换行符(一个新的< em> group ),所以我们最终匹配线的其余部分。

用自己替换匹配的行(整个匹配 - $0换行符 - $0\n

See it illustrated here at regex101