title: Split a string with unescaped delimiter only
body: <p>I want to split a string with <code>,</code> as delimiter.  My problem is that in some cases the input may contains commas. Changing the delimiter is not an option. I want users to be able to escape comma with <code>\</code>, and so I want to split only on <code>,</code> <strong>but not</strong> on <code>\,</code> like so:</p>
  
  <pre><code>str="1,10,100,1\,000,10\,000,100\,000"
  while [[ ${#str} -gt 0 ]]; do
      #Get index of delimiter
      index=$(echo "$str" | grep -boP '(?&lt;!\\),' | head -c 1)
  
      #If index is empty, there is nothing to do
      if [[ -z "$index" ]]; then
          echo "$str"
          break
      fi
  
      #Get the next string we're looking for
      echo "$str" | cut -c1-$index
      #Cut the original string
      str=$(echo "$str" | cut -c$(($index+2))-${#str})
  done
  </code></pre>
  
  <p>This is currently printing:</p>
  
  <pre><code>1
  10
  100
  1\,000
  10\,000
  100\,000
  </code></pre>
  
  <p>But I want it to print:</p>
  
  <pre><code>1
  10
  100
  1,000
  10,000
  100,000
  </code></pre>
  
  <p>I can now use <code>sed</code> to replace <code>\,</code> with <code>,</code> but this entire solution seems quite bulky for relatively simple problem. Is there a better way to do this?</p>