A simple state-machine regex matcher