notepad++editplus

How i can to delete all after last word no.x?


How i can to delete all after last word no.4?

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

So i want to remove word5 and word14


Solution

  • Explanation:

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

    Result for given example:

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

    Before:

    enter image description here

    After:

    enter image description here