How can I match a regex in a switch statement?
<p>I'm trying to match tokens against a switch statement in a function, and one of those tokens needs to be able to identify <em>any</em> string or <em>any</em> numbers defined by the regex in the code below.  </p>

<p>Basically, is it possible to define a regex against a case like <code>case "[a-z]+":</code></p>

<p>Clearly the way I have it now, my pattern is not reachable unless I pass <code>STRING</code> or <code>NUMBER</code> as an argument.</p>

<pre><code>public Token analyzeToken(String token) {
      Token tokenType = null;     

      switch (token) {

         case "STRING":
            Pattern p = Pattern.compile("[a-z]+");
            Matcher m = p.matcher(token);
            if(m.matches()) {
               tokenType = Token.STRING;
               break;
            }
         case "NUMBER":
            Pattern p = Pattern.compile("[0-9]+");
            Matcher m = p.matcher(token);
            if(m.matches()) {
               tokenType = Token.NUMBER;
               break;

         case "(":
            tokenType = Token.LEFT_PAREN;
            break;
         case ")":
            tokenType = Token.RIGHT_PAREN;
            break;
         case ".":
            tokenType = Token.PERIOD;
            break;
         case ":":
            tokenType = Token.COLON;
            break;
         case ";":
            tokenType = Token.SEMICOLON;

         default:
            tokenType = TOKEN.UNKNOWN;
            break;

      }
   }
</code></pre>