7

How to append and prepend a character at start and end of each file line?

I have this file structure:

140","Bosnia
160","Croatia
170","Serbia
180","Montenegro
200","Slovenia

What I need is to add a double quote " at the start and at the end of each file line, using regular expressions in Notepad++ editor.

Thanks!

3 Answers3

23

Just search for

(.*)

and replace with

"\1"

with regular expression option activated. Regular expressions are working only on a row bases, so (.*) matches the complete row and because of the brackets around you can access the match using \1.

stema
  • 90,351
  • 20
  • 107
  • 135
5

Try searching ^(.*)$ and replacing by "$1".

bye ;)

Kai
  • 38,985
  • 14
  • 88
  • 103
aaronroman
  • 820
  • 1
  • 6
  • 10
0

You can match the whole, even an empty line, with

^.*$

You can match a non-empty line with

^.+$

You may match a non-blank line with

^\h*\S.*$

Now, all you need to do to wrap these lines with any text of your choice, you need to use the backreference to the whole match (see Replace with whole match value using Notepad++ regex search and replace):

"$0"
"$&"
"$MATCH"
"${^MATCH}"

If you need to wrap the whole line with parentheses, you will need to escape them since ( and ) are "special" in the Notepad++ replacement pattern, \($&\).

Whenever you need to insert a backslash, make sure you double it, \\$&\\.

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563