Finite Automata Pattern Matching Algorithm