Replace a group (and its child objects) with another group (and its child objects)

I'm trying to write a scene optimisation script that swaps out groups in the scene with groups from an external .max file.

So far my script does this:
1. Collect the groups in my scene as an array (called originalgroups).
2. Import new groups from an external .max file (but only import groups that match the names in originalgroups array)
3. Create a second array containing the imported groups (called newgroups)

For the last step,
How do I replace a group node and all it's child objects with another group and all it's child objects?

Any help would be awesome thanks