Welcome to OGeek Q&A 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 Reply

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...