Use regex everywhere instead of manual parsing

This makes the code smaller and easier to read.