title: How to avoid a loop-switch anti pattern
body: <p>I am writting a regex parser for which, a loop-switch anti-pattern appears to be the only approach. Please ignore actual rules of parsing, as this parsing-logic is just custom made for an internal application, and deviant from common use.</p>
  
  <pre><code> public static boolean match(String regex, String str) {
          int i = 0;
          int j = 0;
  
          while ((i &lt; regex.length() &amp;&amp; j &lt; str.length())) {
  
              switch(regex.charAt(i)) {
  
              case '.' : i++; j++; break;
  
              case '*' : // do something ; break
  
              default  : if (regex.charAt(i) != str.charAt(j)) { return false; }  else {i++; j++};
              }
          }     
     }
  </code></pre>
  
  <p>How can the loop-switch be prevented in such a case ? Is there any design pattern meant for such a purpose ?</p>