in reply to regex large named.conf parsing

Can anyone suggest a better method than the one below, which seems to take forever to match towards the end of the file.

See Matching in huge files for a sliding buffer technique that lets you run a regex that might match multiple lines on a huge file, without needing to pull the entire file into memory. What the technique doesn't support, at least not directly, is doing substitutions. But you might be able to adapt it to your purposes.