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?

0

4 Answers 4

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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.
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.

Comments

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.

Comments

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

1 Comment

This would work except the output should not have a space within the quotes. Bad: ' bla', ' ble' - Good: 'bla', 'ble'.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.