title: Why is Compiler is saying there is no group with name <NUMBER>?
body: <p>I am making Lexical analyzer. LINE 1-30 are imports
  FUNCTION init() just initializes HASHTABLE for keyword.
  enum at LINE 61 "TokenType" specifies the tokens which are going to be taken.
  I am getting an error saying no group with name  when clearly I have declared NUMBER.
  LINE 96 uses the matcher engine to match.
  LINE 97 if a group is matched @ LINE 98 creates a token and returns and matcher moves on to the next one.</p>
  
  <pre><code>public static enum TokenType{
     ADDSUB("[+|-]?"),NUMBER("-?[0-9]+"),
  INCDEC("[[++]|[--]]"),DIVMOD("[/|%]"),
  ID("[_a-zA-Z][_a-zA-Z0-9]*"),
  MUL("[*]+"), WHITESPACE("[ \t\f\r\n]+");
  public final String pattern;
  
      private TokenType(String pattern){
      this.pattern=pattern;
      }
    }
     /*we declare a data structure for holding the token data*/
    public static class Token{
      public TokenType type;
      public String Data;
      public Token(TokenType type,String Data){
          this.type=type;
          this.Data=Data;
      }
      @Override
       public String toString() {
    return String.format("(%s %s)", type.name(), Data);
      }
       }
  
       public static ArrayList&lt;Token&gt; lex(String input) {
  // The tokens to return
          ArrayList&lt;Token&gt; tokens = new ArrayList&lt;Token&gt;();
  
  // Lexer logic begins here
          StringBuffer tokenPatternsBuffer = new StringBuffer();
        for(TokenType tokenType :TokenType.values()){
        tokenPatternsBuffer.append(String.format("|(?&lt;%s&gt;%s)",    tokenType.name(), tokenType.pattern));
  
      Pattern tokenPatterns=Pattern.compile(tokenPatternsBuffer.substring(1));
        // Begin matching tokens
           Matcher matcher = tokenPatterns.matcher(input);
              while(matcher.find())       
      {if(matcher.group(TokenType.NUMBER.name())!=null){ tokens.add(new Token(TokenType.NUMBER,matcher.group(TokenType.NUMBER.name())));
        continue;
    } else if(matcher.group(TokenType.ID.name())!=null){
        if(KW.containsValue(matcher.pattern())){
            System.out.println("y");
  
   tokens.add(new   Token(TokenType.ID,matcher.group(TokenType.ID.name())));
        }
        else{
            System.out.println("n");
  
   tokens.add(newToken(TokenType.ID,matcher.group(TokenType.ID.name())));  
        continue;
        }
       }
          }
  
       }
       return tokens;
               }
  </code></pre>