1

我怎样才能删除最后一个单词 4 之后的所有内容?

word1 word2 word3 word4 word5
word6 word7 word8 word9
word10 word11 word12 word13 word14 

所以我想删除 word5 和 word14

4

2 回答 2

1
  • Ctrl+H
  • 找什么:^(?:\S+\h+){4}\K.*$
  • 用。。。来代替:LEAVE EMPTY
  • 检查环绕
  • 检查正则表达式
  • 取消选中. matches newline
  • Replace all

解释:

^               # beginning of line
  (?:           # start non capture group
    \S+         # 1 or more non space character
    \h+         # 1 or more horizontal space
  ){4}          # end group, must appear 4 times
  \K            # forget all we have seen until this position
  .*            # 0 or more any character but newline
$               # end of line

给定示例的结果:

word1 word2 word3 word4 
word6 word7 word8 word9
word10 word11 word12 word13 

前:

在此处输入图像描述

后:

在此处输入图像描述

于 2018-12-26T13:15:50.813 回答
0

您可以使用下一个模式进行替换

搜索

([\w]+ [\w]+ [\w]+ [\w]+).+$

代替

\1

录制的截屏视频

通过搜索,我们选择前四个单词并将它们放入一个组中。直到行尾的所有其他符号不受影响

通过替换,我们放置匹配的符号而不是整行

于 2018-12-26T12:40:28.173 回答