title: ANTLR4 parsing RegEx
body: <p>I am tryingo to parse RegEx and specifically the following:</p>
  
  <pre><code>[A-Z0-9]{1,20}
  </code></pre>
  
  <p>The problem is, i don't know how to make the following grammar work beacuse the Char and Int tokens are both recognizing the digit.</p>
  
  <pre><code>grammar RegEx;            
  
  regEx : (character count? )+ ;
  
  character : Char 
            | range ;
  
  range  : '[' (rangeChar|rangeX)+ ']' ;
  rangeX : rangeStart '-' rangeEnd ;
  rangeChar : Char ;
  rangeStart : Char ;
  rangeEnd : Char ;
  
  count : '{' (countExact | (countMin ',' countMax) ) '}' ;
  countMin : D+ ;
  countMax : Int ;
  countExact : Int ;
  
  channels {
    COUNT_CHANNEL,
    RANGE_CHANNEL
  }
  
  Char : D | C ; 
  Int : D+ -&gt; channel(COUNT_CHANNEL) ;
  
  Semicolon : ';' ;
  Comma : ',' ;
  Asterisk : '*' ;
  Plus : '+' ; 
  Dot : '.' ;  
  Dash : '-' ;
  //CourlyBracketL : '{' ;
  //CourlyBracketR : '}' ;
  
  WS : [ \t\r\n]+ -&gt; skip ; // skip spaces, tabs, newlines, \r (Windows)
  
  fragment D : [0-9] ;
  fragment C : [a-zA-Z] ;
  </code></pre>
  
  <p>Now, I'm a noob and I am lost wether should I try lexer modes, channels some ifs or what is the "normal" approach here.
  Thanks!</p>