Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

replace - Remove everything except for first 3 words of a line in Notepad++

I have a lengthy text document and I would like to remove everything except for the first 3 words of each line. I've seen a few answered questions that allow you to do this but only retaining the first word. I'm just wondering if it is possible with the first 3 instead. Here is an example:

(original)

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

(what I would like to keep)

hello how are
this is just
today is a

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
  • Ctrl+H
  • Find what: ^w+h+w+h+w+K.*$
  • Replace with: LEAVE EMPTY
  • CHECK Wrap around
  • CHECK Regular expression
  • Replace all

Explanation:

^           # 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
$           

Screenshot (before):

enter image description here

Screenshot (after):

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...