0

I want to use a regex to identify commas that occur within double quotes, and then I will want to strip those commas out. There can be any number of commas within the quotes, and there can be multiple sets of quotes on a line. So here's an example of input and desired output:

dog, "apple, three", tree, cat, "orange, yellow", leaf   =>   
dog, "apple three", tree, cat, "orange yellow", leaf

dog, "apple, three, blue", tree, cat, "orange, jar, yellow", leaf   =>   
dog, "apple three blue", tree, cat, "orange jar yellow", leaf

I want to strip out just the commas within the quotes, not the ones outside, and keep the rest as is.

user3060126
  • 461
  • 1
  • 4
  • 13
  • see https://regex101.com/r/vW2pQ7/21 – Avinash Raj Dec 23 '14 at 17:16
  • I'd highly recommend taking advantage of the CSV class, which comes with Ruby. Use it to read a line, then iterate over each field returned, stripping commas, either using `tr(',', '')` or `delete(',')` on the field. Then have CSV regenerate the comma-delimited output. – the Tin Man Dec 24 '14 at 00:49

0 Answers0