A million thanks to you good sir.
I think understand what's happening. Basically you divide the rule string using $ as the delimiter and then loop through each snippet comparing it to the first same number of letters in the input string and then you delete the length of the snippet plus one character, the delimiter, from the input string. That should work perfectly for what I'm trying to do.
Thanks for the help and thanks for the warm welcome