regex: General style tweaks.

For loops are nicer than manual whiles, etc.