title: Performance and readability of RegEx using positive look ahead
body: <p>I am validating following strings with regular expressions in C#:</p>
  
  <blockquote>
    <p>[/1/2/]<br/>
    [/1/2/];[/3/4/5/]<br/>
    [/1/22/333/];[/1/];[/9999/]</p>
  </blockquote>
  
  <p>Basically it's one or more group of square brackets separated by semi-colon (but not at the end). Each group consists out of one or more numbers seperated by slashes. There are no other characters allowed.</p>
  
  <p>These are two alternatives:</p>
  
  <pre class="lang-regex prettyprint-override"><code>^(\[\/(\d+\/)+\](;(?=\[)|$))+$
  
  ^(\[\/(\d+\/)+\];)*(\[\/(\d+\/)+\])$
  </code></pre>
  
  <p>The first version uses a positive look ahead and the second version duplicates part of the pattern.</p>
  
  <p>Both RegEx-es seem to be ok, do what they should and aren't very nice to read. ;) </p>
  
  <p>Does anybody have an idea for a better, faster and more easy to read solution? When I was playing around in <a href="https://regex101.com/#" rel="nofollow">regex101</a> I realized that the second version uses more steps, why?</p>
  
  <p>At the same time I realized that it would be nice to count the steps used in a C#-RegEx. Is there any way to achieve this?</p>