Use string methods to replace the regular expression.

Fixes #939.

Exploit the fact that the interesting parts of the environment variable name are separated by `_` to extract the information we want by splitting the string into pieces.