Attempting to save matches before substitutions.
First working version using multiple passes of element matching.