Are quotation marks sequential? If I do not understand your requirement, this will work ...
str = str.replace(/\"\"?/g, '""')
Explanation: Matches one quote, optionally followed by another quote, and replaces one / both with two quotation marks.
Example: http://jsfiddle.net/aR6p2/
Or, alternatively, if it's just a matter of adding a quote if there is an odd number of quotes in the string ...
var count = str.split('"').length - 1
str = str + (count % 2 == 0 ? '' : '"')
source
share