Search code examples
compilationcompiler-constructionflex-lexerlexical-analysis

Meaning of ^ in flex


I have got a question about flex. In my notes, in a sample code fragment it says the following:

[^ \t\n]+ printf("saw a word\n");

I do not understand what that code means, and how it corresponds to a word. It looks like \t means when we see a blank, and \n means when we see the newline character, but what is the meaning of ^ at the beginning, and what exactly [^ \t\n]+ means? I would appreciate if somebody can explain.


Solution

  • [] is a character group and matches all characters specified in it. ^ in that context inverts the whole thing, and the character group matches everything but the characters specified. So in this case, it matches everything but a space, tab or newline character.