Page 1 of 1

Add double quotes around words, add comms between words

Posted: Mon Dec 20, 2010 1:00 am
by scottbass
Hi,

I'm wanting to write a macro to add double quotes around words, and add commas between words. In actuality, it's just a regular expression search and replace. The purpose is to build an "IN ( )" expression in SQL.

Say I have this text:

Code: Select all

AAA BBB CCC
DDD    EEE    FFF
GGG HHH III
What I want to do is select the first two lines, then generate this desired text:

Code: Select all

"AAA","BBB","CCC",
"DDD","EEE","FFF"
GGG HHH III
Note the collapsing of extra space in the 2nd line.

All help greatly appreciated, and a free beer to you the next time you're in Sydney.

Thanks,
Scott

Posted: Mon Dec 20, 2010 10:08 am
by ben_josephs
1. Enclose the words in quotes:
Find what: [A-Z]+
Replace with: "\0"

[X] Regular expression

Replace All
2. Replace the white space with commas:
Find what: _+ [Replace the underscore with a space]
Replace with: ,

[X] Regular expression

Replace All