title: Regex expression to validate a formula
body: <p>I am new to regex and currently building web application in Java.I have the following requirements to validate a formula:</p>
  
  <ol>
  <li>Formula must start with “T”</li>
  <li>A formula can contain the following set of characters:
  
  <ul>
  <li>Digit: 0 - 9</li>
  <li>Alpha: A - Z</li>
  <li>Operators: *, /, +, -</li>
  <li>Separator: ;</li>
  </ul></li>
  <li>An operator must always be followed by a digit</li>
  <li>The character “T” must always be followed by a digit or an alpha.</li>
  <li>The separator must always be followed by “T”.</li>
  <li>The character “M” must always be followed by an operator.</li>
  </ol>
  
  <p>I manage to build up the following expression as shown below:</p>
  
  <pre><code>^[T][A-Z0-9 -- \\+*;]*
  </code></pre>
  
  <p>But i don't know how to add the following validation with regex above:</p>
  
  <ol>
  <li>An operator must always be followed by a digit</li>
  <li>The character “T” must always be followed by a digit or an alpha.</li>
  <li>The separator must always be followed by “T”</li>
  <li>The character “M” must always be followed by an operator.</li>
  </ol>
  
  <p>Valid sample: <code>TA123;T1*2/32M+</code></p>
  
  <p>Invalid Sample: <code>T+qMg;Y</code></p>