Flex a tool for generating text scanners in C. The input file read by Flex specifies a set of rules (code to be executed when a pattern is found) which describe the scanner to be generated. The output of Flex is a C source file which can be compiled and linked with your sources, giving to your executable the scanning capabilities tailored to your needs.
Generally, Flex is used in combination with a parser generator, like Bison.