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.
Click http://web.archive.org/web/20120915222417/http://www.diku.dk/hjemmesider/ansatte/torbenm/Basics/basics_lulu2.pdf link to open resource.