regex: Make some general tweaks

Mostly code style e.g. avoiding `~` and using `for` + iterators.