Torben Ægidius Mogensen's "Basics of Compiler Design, Chapter 2: Lexical Analysis"

Read section 2.9.1. Scanners are usually not written anew, but are generated by tools called scanner (or parser) generators.