title: Regex - Split String on Comma, Skip Anything Between Balanced Parentheses
body: <p>Need to write a regex in R - Perl which would split string on comma ',' but skip all instances of comma in between round parenthesis. The challenge is to ensure that the parentheses are balanced, i.e. close bracket maps back to its open bracket.</p>
  
  <p>In the below regex code, everything works perfectly, except if you notice - Parentheses are not balanced, an inner end bracket is being considered for an outer start bracket</p>
  
  <pre><code>text &lt;- "PEANUTS (PEANUTS, PEANUT OIL AND/OR COTTONSEED OIL AND/OR CANOLA OIL AND/OR SOYBEAN OIL, SALT), GOLDEN RAISINS (RAISINS, SULFUR DIOXIDE), DRIED CRANBERRIES (CRANBERRIES, SUGAR, CITRIC ACID, SUNFLOWER OIL (PROCESSING AID), ELDERBERRY JUICE CONCENTRATE (COLOR)), ALMONDS (ALMONDS, PEANUT OIL AND/OR COTTONSEED OIL AND/OR CANOLA OIL AND/OR SOYBEAN OIL, SALT), MACADAMIAS (MACADAMIAS, MALTODEXTRIN, SALT)"
  
  strsplit(text, '\\([^*)^)]*\\)(*SKIP)(*F)|\\,', perl=T)
  </code></pre>
  
  <p>Using the above regex code, <i>Dried Cranberries</i> is not being splitted correctly. Please refer to the output screenshot here: <a href="https://i.stack.imgur.com/5mgTR.png" rel="nofollow noreferrer">Regex Code Output</a></p>
  
  <p>Any help here would be much appreciated.. Thank you!</p>