title: Regex: how to determine odd/even number of occurrences of a char preceding a given char?
body: <p>I would like to replace the <code>|</code> with <code>OR</code> only in unquoted terms, eg:</p>
  
  <pre><code>"this | that" | "the | other" -&gt; "this | that" OR "the | other"
  </code></pre>
  
  <p>Yes, I could split on space or quote, get an array and iterate through it, and reconstruct the string, but that seems ... inelegant.  So perhaps there's a regex way to do this by counting <code>"</code>s preceding <code>|</code> and obviously odd means the <code>|</code> is quoted and even means unquoted.  (Note: Processing doesn't start until there is an even number of <code>"</code> if there is at least one <code>"</code>).</p>