Automata method for String Matching