I would like to keep only the first word of each line within Notepad ++. For an example, please consider the situation where I have these lines

aleag greats broa
abro gdert gfherr httowpw
asteruso dgheur graterf

Want I would like have left is this

How do I do this? Either using notepad++ or something else.

  • 3
    Notepad++ allows regular expression to find match [ use CTRL+F ]. You can write regular expression to match everything after face space character and replace it with nothing. – mnmnc Dec 17 '12 at 11:02

I've only just looked at a reference sheet, so there's probably a better way to do this, but you could do something like this with the Replace dialog (Ctrl+H):

Find: ([0-9a-zA-Z]*)([0-9a-zA-Z ]*$)
Replace: \1

The way I read it is basically:
[0-9a-zA-Z] : match an alphanumeric character
* : keep matching them
[0-9a-zA-Z ] : match an alphanumeric character or a space
$ : match the end of the line
() : "holds" a match in a variable. The first () holds a match in \1, the second in \2 (which we don't need).

Since the first () is "holding" the match you want, that will be what you are replacing the text with. It does this for each line if you hit Replace All.

wordpad++ find replace


A similar solution to the one Louis suggested is to again use Regular expression search within Notepad++, with the search parameter:


And replace with:


The advantage/difference of this version over Louis' one is that it will also match first words like Apostrophy's or Colons: or Hyphen-ated where there are non alphanumeric characters.

This matches everything from the start of each line (the ^ symbol means start of line). It finds at least one character (.+? is non-greedy match one or more characters) stopping as soon as it finds a blank (\s is blank/space). It then carries on matching everything else in the line (.* is match zero or more characters), up to the end of the line ($ is end of line).

The \1 will then only keep the section matched within the brackets, I.E. everything before the first space in the line.

N.B. make sure the . matches newline checkbox is unticked, or you will only get the first word in the whole document.


As you don't know any languages to program in, you can do this in Excel

Paste each line into Column A.

Then, in column B, paste

=LEFT(A1,SEARCH(" ",A1)-1)

enter image description here

  • I am not good with programming languages sir,so something else means any program that i can download and use to do what i need to be done – Habeeb Dec 17 '12 at 10:51

An even simpler solution is to use " .*" Just open Notepad++, Choose regular expression's in search and replace, enter the below and then click replace all:

Find:  .*

Note that, the is a space in front of the dot and that replace is blank.

enter image description here


second case, if you wanna delete the first word at the beginning of each line

FIND: ^\w+

REPLACE BY: (leave empty)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.