我如何删除第4个字之后的所有内容?
word1 word2 word3 word4 word5
word6 word7 word8 word9
word10 word11 word12 word13 word14
所以我想删除word5和word14
答案 0 :(得分:1)
^(?:\S+\h+){4}\K.*$
LEAVE EMPTY
. matches newline
说明:
^ # 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
答案 1 :(得分:0)
您可以使用下一个替换样式进行
搜索
([\w]+ [\w]+ [\w]+ [\w]+).+$
替换
\1
通过搜索,我们选择前四个单词并将它们分组。直到行尾的所有其他符号均不受影响
通过替换,我们将匹配的符号代替整行