title: preg_match only some numbers
body: <p>I want to write preg_match function for this BNF grammar.</p>
  <blockquote>
  <p>EXP    ::= EXP  + TERM   | EXP - TERM    | TERM</p>
  <p>TERM   ::= TERM * FACTOR | TERM / FACTOR | FACTOR</p>
  <p>FACTOR ::= ( EXP ) | DIGIT</p>
  <p>DIGIT  ::= 0 | 1 | 2 | 3</p>
  </blockquote>
  <p>I tried to write it this way</p>
  <blockquote>
  <p>$pattern  = &quot;|[0-3+-()*/]+\$$|&quot;;</p>
  </blockquote>
  <p>but the problem with this is , it accepts string 33$ which is not valid as per my grammar
  so as per my grammar 1+22$ should not be valid because number should be 0|1|2|3.</p>
  <p>what mistake I am making? can somebody please help me.</p>
  <p>Edit:</p>
  <p>Example:
  1+22$ should be invalid string because I just want numbers 0,1,2,3 but not any number &gt; 3</p>
  <p>Thank you.</p>