Add double quotes around words, add comms between words

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
scottbass
Posts: 17
Joined: Thu Nov 19, 2009 5:40 am
Location: Sydney, Australia

Add double quotes around words, add comms between words

Post 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
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Post 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
Post Reply