title: Stumped on Regex with zero-width positive lookbehind assertion
body: <p>I have a string, and I would like to find all greater-than characters that are <em>not part of</em> an HTML tag.</p>
  
  <p>Ignoring CDATA, etc., this should be easy: find any ">" character that either has no "&lt;" before it, or there is another ">" between them.</p>
  
  <p>Here's the first attempted solution I came up with:</p>
  
  <pre><code> (?&lt;=(^|&gt;)[^&lt;]*)&gt;
  </code></pre>
  
  <p>I <em>think</em> this should look for any ">" where there are no "&lt;" characters to the left of it, either back to the beginning of the string, or back to the previous ">".</p>
  
  <p>I tried phrasing it negatively as well:</p>
  
  <pre><code> (?&lt;!&lt;[^&gt;]*)&gt;
  </code></pre>
  
  <p>I.e., a ">" that is nor preceded by a "&lt;" unless that is only followed by non-">" characters.</p>
  
  <p>I suspect I'm just twisted up in my head about how lookbehinds work.</p>
  
  <p>Unit Tests:</p>
  
  <pre><code> No match in: &lt;foo&gt;
   No match in: &lt;foo bar&gt;
   Match in: &lt;foo&gt; bar&gt;
   Match in: foo&gt; bar
   Match in: &gt;foo
   Two matches in: foo&gt;&gt;
   Two matches in: &lt;foo&gt; &gt;bar&gt;
  </code></pre>
  
  <p>Use case: I'm scrubbing HTML from a wiki-like form field that <em>accepts</em> some HTML tags, but the users are not terribly HTML savvy and sometimes enter unescaped ">" and "&lt;" literals for actual less-than and greater-than meanings. My intent is to replace these with HTML entities, but only if they aren't part of an HTML tag. I know there's the possibility of them entering text like "Heigh is &lt; 10 and > 5", which would break this, but that's an edge case I can work around or live with.</p>