Earlier quoted context omitted.
This is why I want any ML device to be able to explain itself. It could train on your before-and-after examples and come up with a list of what it thinks you want it to do. For your example, it could list: “Remove interior spaces from each item” or it could say: “Remove the middle character from any 7-character strings to make them 6 characters in length” You would be able to do something with that.
Neural nets are infamous for not doing this. Learning algorithms that produce decision trees are usually used in this situation.
You could even say that it only needs to approximately reproduce the output with some tunable error threshold, which might give you leeway for finding more comprehensible and simpler trees.