The substitution process is non-trivial, as Jim Rose describes, but it might be possible to come up with several alternatives and test each of them.
Non trivial, but I think doable if one is willing to make a few assumptions and not worry too much about the hard cases. I might have a go at it myself but I've got quite a backlog of stuff to do at the moment.