Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to remove all the words that ending with abc


111abc 222def 333abc 444def 555abc 666def

From here I want to delete all the words that ending with abc.

so I tried this


But this will replace only abc

How to delete that all words ending with abc?

share|improve this question
up vote 4 down vote accepted

If you want to remove the whole word, and if your sample is complete, then you want to use this regexp:


It removes every bit consisting of 3 digits followed by abc.

share|improve this answer
It's showing E486: Pattern not found: [0-9]{3}abc – max Sep 15 '12 at 10:34
My bad, I forgot to escape the curly braces. Edited. – m4573r Sep 15 '12 at 10:41
Thanks a lot it's working... – max Sep 15 '12 at 10:48

If all the words you want to delete consist of three digits followed by the character sequence "abc" you can go with @m4673r's suggestion. For a more general approach I'd suggest this instead:


This will remove any word (regardless of characters/length) that ends with the character sequence "abc" (111abc as well as FOOBARabc or just abc).

share|improve this answer

Ansgar's answer is plain right.
I'll explain it's parts to make it a methodology more than a recipe because I think that regular expressions are somehow cryptic.


is a vim substitution command.
It means "in the current line (use %s for all lines) substitute the matches of the regular expression \<\S*abc\> (delimited by the first two "/"s by the text contained between the last two "/"s, i.e., nothing. The ending "g" is for global and means to replace all the matches instead of only the first one.

The regexp is enclosed in escaped angle brackets \< and \>. These are word boundaries, meaning that the regexp will match text only within single words. Think that vim will split the text in words before attempting to match each one.
The escaped uppercase S is for non-witespace. \s (lowercase) matches whitespace (spaces and tabs) while \S (uppercase) matches all other.
Hence, \S* means "non-whitespace characters zero or more times".
The abc part simply matches that exact characters sequence.

Putting it all together, the regexp matches whole words made up of any sequence of characters followed by abc, as max wanted.

Because of the way vim thinks of words, the any sequence of characters will not contain spaces and other characters that are word boundaries. The other characters list depends on the file type being edited and can be seen typing :set iskeyword enter. This is the information used to split the text in words.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .