title: Regex for lines containing an odd number of pipe characters
body: <p>I'm cleaning up a LaTeX file, and I'm in a situation where I need to distinguish absolute value |x| from the set "such that" symbol i.e. {x | x &lt; 0}.</p>
  
  <p>The first step for me is to find all lines containing an odd number of | characters (i.e. the pipe symbol).</p>
  
  <p>In principle, I know how to do this, but I've tried the following regex command with no luck.</p>
  
  <pre><code>egrep '^[^\|]*\|([^\|]*\|[^\|]*\|)*[^\|]*$'
  </code></pre>
  
  <p>The idea is that a matching line contains, in order:</p>
  
  <ul>
  <li>The line start</li>
  <li>0 or more non-pipe characters</li>
  <li>Exactly one pipe character</li>
  <li>0 or more copies of text containing exactly 2 pipes</li>
  <li>The line end</li>
  </ul>
  
  <p>However, for some reason this isn't working.
  I run the command on the following file:</p>
  
  <pre><code>\[
  S = \{ x | x &lt; 0}
  y = |x|
  \]
  </code></pre>
  
  <p>and none of the lines match.</p>
  
  <p>I suspect I'm making a silly mistake somewhere, possibly to do with escaping the pipe characters,
  but I'm stumped as to what's wrong.</p>
  
  <p>Can anybody tell me either how to fix this, or provide an alternate expression which matches lines containing an odd number of pipe characters?</p>