 <p>No, you cannot use a regex as a case statement in C. In fact, C has no built-in support for any kind of regular expressions at all<sup>*</sup>. However, you can achieve the same result in terms of speed if you "expand" your regular expressions with fall-through:</p> <pre><code>switch (ch) { case '"'; case ';': case ',': case '(': case ')': case '{': case '}': case ' ': printf("\nSEPARATOR: %c found\n", ch); ch =fgetc(fin); break; case '_': case 'a': case 'b': ... // The other 24 letters go here case 'A': case 'B': ... // Same thing for uppercase letters case 'Z': printf("\nIDENTIFIER: "); ... } </code></pre> <p>Unfortunately, this would result in much longer code. You can convert it to a lookup table, though, which would be less readable, but run roughly as fast:</p> <pre><code>enum { OTHER , ID_START , DIGIT , SEPARATOR }; int map_char(unsigned char c) { static int *lookup_ptr = NULL; static int lookup[256]; if (lookup_ptr == NULL) { for (int i = 0 ; i != 256 ; i++) { if (i=='"; || i==';' || i==',' || ...) { lookup[i] = SEPARATOR; } else if (i=='_' || isalpha(i)) { lookup[i] = ID_START; } else if (isdigit(i)) { lookup[i] = DIGIT; } else { lookup[i] = OTHER; } } lookup_ptr = lookup; } return lookup_ptr[c]; } </code></pre> <p>Now you can use the function as follows:</p> <pre><code>switch (map_char(ch)) { case SEPARATOR: ... break; case ID_START: ... break; case DIGIT: ... break; case OTHER: ... break; } </code></pre> <p><sup>*</sup> Square bracket syntax of <code>scanf</code> functions only looks like regex, but it is not.</p>