Why so complicated with a regex? Could you not simply use `parse_url`?