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 do we achieve the following using replace function in notepad++?

Transforming the following

cow
horse
elephant
camel

into

'cow','horse','elephant','camel'

I know ^ and $ (under Regular Expression) will let me access the beginning and end of the line and therefore I can put the single quotes at the extremes but then how do I append the lines thereafter? Also, I want to do everything (putting quotes and appending) in one go if possible.

Thank you very much for your help.

share|improve this question

2 Answers 2

up vote 3 down vote accepted
  1. Download the latest version, it includes regular expression fixes.

  2. Replace using the regular expression: (.*)[\r\n]* and turn it into '\1',

  3. Remove the last ,, it's not possible to do this inside the regular expression in Notepad++.

share|improve this answer
    
Thanks @Tom . Will you mind explaining a bit on your second step... –  Stat-R Apr 11 '12 at 15:46
    
"fixes" link does not work. –  Daniel Andersson Apr 11 '12 at 16:16
    
@Stat-R: I guess you figured out because of the replace, but it is basically like this: You go to the "replace" dialog and then tick "Regular Expression" and then fill in the two codes I gave you in the two boxes. –  Tom Wijsman Apr 11 '12 at 17:17
    
@TomWijsman: "This page has been deleted"? Well, perhaps it shows that it is no longer an issue since the wiki page is no longer needed, if that is what you mean. –  Daniel Andersson Apr 12 '12 at 6:22
    
@DanielAndersson: Now read the whole line under that. :D –  Tom Wijsman Apr 12 '12 at 9:48

This solution is not a 100% percent solution, but it gets you most of the way there and is very simple. When I want to do this I use the "Extended" search mode on the replace dialog and use \r\n as the search term. In your case you would replace it with ','. That will get you to

cow','horse','elephant','camel

Now you just need to fix the first and last elements manually.

share|improve this answer
    
I tried this before asking my question here but for some reason (??) this did not work for me. I am using NP++(6.1). –  Stat-R Apr 11 '12 at 15:44
    
I just tried it on 6.1 and it worked fine. Make sure you file is using Windows line endings (View->Show Symbol->Show End of Line). You should see a CRLF at the end of each line. If you just see LF change your search term to \n. –  heavyd Apr 11 '12 at 16:00
    
I saw CR and I used \r. It worked. Thanks @heavyd –  Stat-R Apr 11 '12 at 16:22

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.