Enable regex filtering
Add some safe-guards.

While this slows down the script a bit, it also prevents some infinite
loops with garbage input.