Replace commas within quotes

General questions about using TextPad

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

Post Reply
obfusc88
Posts: 8
Joined: Mon Dec 18, 2006 8:50 pm

Replace commas within quotes

Post by obfusc88 »

Problem:
Cannot parse string with comma delimiters. Plan to temp replace some commas with tildes, parse the result, then replace the original commas.

Need help to replace "internal" commas with tildes, and remove double quotes. Would like to do in one RegEx if possible.

Replace commas within double quotes with tildes and eliminate double quotes
Length of double quoted strings may vary

Original string:
red,white,blue,"555,000,000",green,"23,000",yellow,...

Final result:
red,white,blue,555~000~000,green,23~000,yellow,...

The sample line is abbreviated, it could be hundreds of values on the line, it is a database dump

After I have final result each value will go on its own line and the tildes will be replaced with commas. Don't need help with that part.
User avatar
Bob Hansen
Posts: 1516
Joined: Sun Mar 02, 2003 8:15 pm
Location: Salem, NH
Contact:

Post by Bob Hansen »

Was not able to do this in one RegEx, but try this, allows for long strings with 3 commas:

Search for: "([^,]*),*([^,]*),*([^,]*),*([^,]*)"
Replace with: \1~\2~\3~\4

Then remove trailing tildes in center of string:
Search for: ~*,
Replace with: ,

Then remove trailing tildes at end of string:
Search for: ~*\n
Replace with: \n
Hope this was helpful.............good luck,
Bob
Post Reply