4

I have below text line in Notepad ++

Type, Layer, Env, key, action, timestamp, performedBy, desc, 

I want to convert it to

'Type', 'Layer', 'Env', 'key', 'action', 'timestamp', 'performedBy', 'desc', 

I write in find [a-zA-Z]*, and it gives me each comma separated string what shall I enter in replace to have them surrounded by quotes?

mrzasa
  • 22,895
  • 11
  • 56
  • 94
Neha Vari
  • 492
  • 3
  • 14

4 Answers4

7

You can use ([a-zA-Z]*) in find and '\1' or '$1' in replace.

\1 or $1 (in newer versions of n++) means the first captured group.

See also this question.

mrzasa
  • 22,895
  • 11
  • 56
  • 94
  • I needed to include numbers and a period, so `([a-zA-Z0-9\.]+)` worked for me, having * means "empty" matches are included also which in my case didn't make sense. – gakera May 14 '21 at 11:33
4

You can use $0 to refer to the whole match in the replacement pattern, so you could handle your task simply by replacing with :

'$0'

Additionally, I suggest changing your matching pattern to [a-zA-Z]+ instead of [a-zA-Z]* to avoid the risk of adding quotes around zero-width matches.

Aaron
  • 24,009
  • 2
  • 33
  • 57
3

If you search for ([a-zA-Z]*), the () indicates a group you can reference later.

Now you can write '$1', in the replace dialog.

jesper_bk
  • 503
  • 2
  • 9
1

Try:

CTRL+H

Find What: (.*?)(?=,) Replace With: '$1'

Output: 'Type',' Layer',' Env',' key',' action',' timestamp',' performedBy',' desc',

Note: Make sure Search Mode is Regular expression

Developer Guy
  • 2,318
  • 6
  • 19
  • 37
Saleem
  • 8,728
  • 2
  • 20
  • 34
  • This would work except the output should not have a space within the quotes. Bad: ' bla', ' ble' - Good: 'bla', 'ble'. – gakera May 14 '21 at 11:26