naive regexp based on nondeterministic finite automata using scala