title: What regex captures anything between 2 identical characters, but ignoring when those characters are part of a repeated sequence of that character?
body: <h2>Problem</h2>
  <p>I'm trying to look for a pound sign (#) in a string as a start and stop sign for capturing. However, if two or more pound signs occur together (ie: ##), they should be ignored.</p>
  <p>Take for example this source string:</p>
  <pre class="lang-none prettyprint-override"><code>This## is #a test# for ## some ## # things ## around # here.
  </code></pre>
  <p>I expect the regex to find the following:</p>
  <ol>
  <li><code>#a test#</code></li>
  <li><code># things ## around #</code></li>
  </ol>
  <h2>Best attempt</h2>
  <p>My best attempt at the regex is:</p>
  <pre><code>(?!&lt;#)#(?!#)(.+?)(?!&lt;#)#(?!#)
  </code></pre>
  <p>but this captures:</p>
  <ol>
  <li><code># is #</code></li>
  <li><code># for ##</code></li>
  <li><code># #</code></li>
  <li><code># around #</code></li>
  </ol>
  <p>I thought the negative look behinds <code>(?!&lt;#)</code> would prevent using the # character if a previous character in the string was also a pound sign. If I remove them from the regex, the results are exactly the same.</p>
  <p>I thought the negative look aheads <code>(?!#)</code> would prevent using the # character if the next character in the string was also a pound sign. This part at least seems to work as expected since the 2nd result (<code># for ##</code>) ends with two pound signs, indicating it didn't accept the first pound sign as a terminator.</p>
  <h2>Possible solution</h2>
  <p>I could preprocess the string to convert double pound signs into a unique Unicode character (such as U+2A33: ⨳), but this will throw off a character index in the actual application. I suppose I could double the Unicode character to handle that off-by-one.</p>
  <p>But, if I can handle it directly in regex, I can avoid having to preprocess the source string.</p>
  <h2>Conclusion</h2>
  <p>I want to be able to look for a pound sign (#) in a string as a start and stop sign for capturing, unless a pound sign occurs in a string of repeated pound signs. (ie: ##)</p>
  <p>Is that possible? If so, was I close? If not, are there other suggestions to the preprocess solution?</p>