Pattern queries using FSM