97

I have quite a large list of words in a txt file and I'm trying to do a regex find and replace in Notepad++. I need to add a string before each line and after each line.. So that:

wordone
wordtwo
wordthree

become

able:"wordone"
able:"wordtwo"
able:"wordthree"

How can I do this?

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
zuk1
  • 18,009
  • 21
  • 59
  • 63

5 Answers5

189

Assuming alphanumeric words, you can use:

Search  = ^([A-Za-z0-9]+)$
Replace = able:"\1"

Or, if you just want to highlight the lines and use "Replace All" & "In Selection" (with the same replace):

Search = ^(.+)$

^ points to the start of the line.
$ points to the end of the line.

\1 will be the source match within the parentheses.

Jonathan Lonowski
  • 121,453
  • 34
  • 200
  • 199
35

Regular Expression that can be used:

Find: \w.+
Replace: able:"$&"

As, $& will give you the string you search for.

Refer: regexr

Mukul Aggarwal
  • 1,515
  • 20
  • 16
31

Why don't you use the Notepad++ multiline editing capabilities?

Hold down Alt while selecting text (using your usual click-and-drag approach) to select text across multiple lines. This is sometimes also referred to as column editing.

You could place the cursor at the beginning of the file, Press (and hold) Alt, Shift and then just keep pressing the down-arrow or PageDown to select the lines that you want to prepend with some text :-) Easy. Multiline editing is a very useful feature of Notepad++. It's also possible in Visual Studio, in the same manner, and also in Eclipse by switching to Block Selection Mode by pressing Alt+Shift+A and then use mouse to select text across lines.

Peter Perháč
  • 20,434
  • 21
  • 120
  • 152
  • 1
    +1 This is really great, I had no idea you could do this. Is it possible to append something to the end of each line, when the length of each line is different? For example, when the 'column' width varies, it would be neat if you could append text to each line. I have a list of functions and I need to append "();" to each line but each function name is a different width. I am currently using a Macro to do this, thanks! – SSH This Mar 20 '12 at 21:45
  • 5
    for appending is probably best to just use simple find/replace using the "Extended" search mode. You can search for line ending, e.g. `\r\n` and replace that with `\r\n` – Peter Perháč Mar 20 '12 at 21:52
  • This is actually a really great solution, especially with the above APPEND comment. – Chuck Le Butt May 18 '12 at 10:31
  • 2
    This is useful for prefixing, but not so useful if you want to postfix mixed-length lines (append at the end). I wish Notepad++ has a built-in "Modify Lines" command like in Notepad2, which allows you to select the lines, press Alt+M, and add text before and/or after each line. – thdoan Jun 23 '15 at 09:16
5

Use a Macro.

Macro>Start Recording

Use the keyboard to make your changes in a repeatable manner e.g.

home>type "able">end>down arrow>home

Then go back to the menu and click stop recording then run a macro multiple times.

That should do it and no regex based complications!

Rob Stevenson-Leggett
  • 35,279
  • 21
  • 87
  • 141
1

In visual studio code i found that simple regex as ^ worked.

luky
  • 2,263
  • 3
  • 22
  • 40