Avoid endless loops when pressing Tab

fix #29
Syntax: fix regex match, some cleanup