title: RegEx for the following string
body: <p>I am trying to create a regex for an ID with the following rules:</p>
  
  <ol>
  <li>Starts with A-Z, one or more times. (Main ID, mi)</li>
  <li>Followed with an optional dash. (delimiter)</li>
  <li>Followed with 0-9, one or more times. (Sub ID, si)</li>
  <li>Followed with an optional dash or dot. (delimiter)</li>
  <li>Followed with an optional a-z or 0-9, one or more times. (Main category, mc)</li>
  <li>Followed with an optional dash or dot. (delimiter)</li>
  <li>Followed with an optional a-z or 0-9, one or more times. (Sub category, sc)</li>
  </ol>
  
  <p>The delimiters <strong>can be</strong> omitted if the ID is alternating alpha and numeric (A-01a1, A1.a.1). Delimiters is <strong>required</strong> if succeeding parts are both alpha or both numeric (A-1.1a, A1.2.3, A1a.a).</p>
  
  <p>Here is what I have:</p>
  
  <pre><code>(?P&lt;mi&gt;[A-Z]+)-?(?P&lt;si&gt;[0-9]+)[\-\.]?(?P&lt;mc&gt;[a-z0-9])*[\-\.]?(?P&lt;sc&gt;[a-z0-9])*
  </code></pre>
  
  <p>Here is the result when I tried it:</p>
  
  <pre><code>ID      mi  si  mc  sc
  A1      A   1
  A001    A   001
  AB-01   AB  01
  A1aa    A   1   a      &lt;&lt;&lt;&lt;&lt; mc=aa
  A-01a1  A   01  1      &lt;&lt;&lt;&lt;&lt; mc=a sc=1
  A-1.1a  A   1   a      &lt;&lt;&lt;&lt;&lt; mc=1 sc=a
  A1.a1   A   1   1      &lt;&lt;&lt;&lt;&lt; mc=a sc=1
  A1.a.1  A   1   a   1
  A1.2.3  A   1   2   3
  A1a.a   A   1   a   a
  </code></pre>