Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

How can I replace different last words in a line in Notepad++?


This is line one
This is line two
This is line three

Replace with:

This is line /one/
This is line /two/
This is line /three/


share|improve this question

If your goal is to surround the last word in a line with slashes, you can accomplish this task very easily by using regular expressions: In your Notepad++ window press Ctrl+F, choose the tab titled 'Replace' and select 'Regular Expression' search mode.

Use (\w+)$ as your search pattern in the 'Find what' field. Because of the parentheses Notepad++ will create a backreference meaning that the matched string inside the parentheses will be stored for further use.

  1. \w matches any word character (alphanumeric + underscore)
  2. + is a greedy quantifier and matches the previous item once or more, as many times as possible.
  3. $ Matches at the end of the string the regex pattern is applied to, in this case before line breaks.

In your case you'd use the following pattern in your 'Replace with' field: /\1/. \1 references the stored match from your first parentheses.

A good place to start with regular expressions is You can try your regular expressions at RegExr.

share|improve this answer
Thank you. It seems for a newby I was on the right track, well almost (-: Also thanks for the Expressions links. – user149097 Jul 30 '12 at 14:31

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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