Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

e.g.

This is line one
This is line two
This is line three
etc.

Replace with:

This is line /one/
This is line /two/
This is line /three/
etc.

Thanks.
Marco

share|improve this question

1 Answer 1

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 Regular-Expressions.info. 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

 
discard

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.