title: Regex to find and replace single quotation marks in strings separated by a comma and enclosed in quotes
body: <p>I'm using Sublime Text 3 and I have a CSV file which contains single quotation:</p>
  
  <p><strong>Input:</strong></p>
  
  <pre><code>"col1", "col2", "col3", "col4", "col5"
  "Cakes", "5" Carrots", "Pineapples'", ""Eggs"", "Apple 5" and 10""
  ...
  </code></pre>
  
  <p>Using regular expressions I would like to "neutralise" but not remove the out of place single quotations (eg. <code>5" Carrots</code>, <code>""Eggs""</code>) and apostrophes (eg. <code>Pineapples'</code>).</p>
  
  <p>By neutralise I specifically mean to place <code>\"</code> in front of each single quotation/apostrophe so the output is:</p>
  
  <p><strong>Output:</strong></p>
  
  <pre><code>"col1", "col2", "col3", "col4", "col5"
  "Cakes", "5\"" Carrots", "Pineapples\"'", "\""Eggs\""", "Apple 5\"" and 10\"""
  ...
  </code></pre>
  
  <p><strong>Progress so far:</strong>
  I think I have 2 pieces needed to solve the puzzle. </p>
  
  <p>Firstly, I can find and replace the quotations for each individual field on its own using the regular expression <code>(".*)(["])(.*")</code>
  Example:</p>
  
  <p><em>Input:</em> <code>"Hello 5" World"</code> <em>Find:</em> <code>(".*)(["])(.*")</code> <em>Replace:</em> <code>\1\\\""\3</code>
  <em>Output:</em> <code>"Hello 5\"" World"</code>. To reproduce this you need to have regex and wrap options selected on the sublime find and replace toolbar.</p>
  
  <p>Secondly, I can find each field in a csv file (opened up in Sublime) using the regular expression <code>([^,\n]+)</code>. See <a href="https://stackoverflow.com/questions/24741214/regex-to-find-strings-separated-by-comma-and-then-add-quotes">this</a> previous question for more info.</p>
  
  <p>The question is how can I use both of these techniques (or others if needed) to get a regex to find and a regex to replace each field which has a single quotation marks (i.e. precede it by <code>\"</code>).</p>
  
  <p>If you don't think this can be done through sublime and regular expressions it would be great if you could suggest a way to do this.</p>
  
  <p><strong>Further Details:</strong>
  For absolute clarity a solution should contain a regular express that finds each field in the CSV file (opened in sublime) that has a single quotation mark in. Then there should be a regular expression that inserts before each quotation mark the string <code>\"</code>.</p>