My biggest problem with this was the post processing. I've always had a problem with manipulating student input (RTFM time.) Your answer is gold.
I see now the failures in my approach (I also forgot the escaping of the +, bad at regex, among other things.) What you have done with contextReaction.pl covers all of this and more. I went through your suggestions here, wrote a problem, it is NOT a good approach (it sorta worked, but not well, too many instructions needed to be issued to students to get things to work.)