首页 > 解决方案 > 删除除 Notepad++ 中一行的前 3 个单词之外的所有内容

问题描述

我有一个冗长的文本文档,我想删除除每行前 3 个单词之外的所有内容。我已经看到了一些已回答的问题,这些问题允许您这样做,但只保留第一个单词。我只是想知道前3个是否有可能。这是一个例子:

(原来的)

hello how are you today
this is just a test
today is a great day

(我想保留的)

hello how are
this is just
today is a

标签: replaceformattingnotepad++

解决方案


  • Ctrl+H
  • 找什么:^\w+\h+\w+\h+\w+\K.*$
  • 用。。。来代替:LEAVE EMPTY
  • 检查 环绕
  • CHECK 正则表达式
  • Replace all

解释:

^           # beginning of line
    \w+         # 1 or more word character
    \h+         # 1 or more horizontal space
    \w+         # 1 or more word character
    \h+         # 1 or more horizontal space
    \w+         # 1 or more word character
    \K          # forget all we have seen until this position
    .*          # 1 or more any character but newline
$           

截图(之前):

在此处输入图像描述

截图(之后):

在此处输入图像描述


推荐阅读