title: Java regex match pattern with priority
body: <p>I am using a system where &amp; followed by a certain letter or number represents a color.<br>
  Valid characters that can follow &amp; are <code>[A-Fa-fK-Ok-or0-9]</code></p>
  
  <p>For example I have the string <code>&amp;aThis is a test &amp;bstring that &amp;ehas plenty &amp;4&amp;lof &amp;7colors.</code></p>
  
  <p>I want to split at every &amp;<em>x</em> while keeping the &amp;<em>x</em> in the strings.<br>
  So I use a positive lookahead in my regex<br>
  <code>(?=(&amp;[A-Fa-fK-Ok-or0-9]))</code><br>
  That works completely fine, the output is:</p>
  
  <pre>&aThis is a test 
  &bstring that 
  &ehas plenty 
  &4
  &lof 
  &7colors.</pre>
  
  <p>The problem is that the spot that has two instances of &amp;<em>x</em> right next to each other should not be split, that line should be <code>&amp;4&amp;lof</code> instead.</p>
  
  <p>Does anyone know what regex I can use so that when there are two of &amp;<em>x</em> next to each other that they are matched together. Two instances of the color code should have priority over a single instance.</p>