Hi,
I may be prepared to have a go but there is a condition!
Have you given all the possible format variations? The last time you started off with a fairly straight forward question and I came up with a simple algorithm (the table) as a starting point.
You then proceeded to drip feed more permutations which I tried to incorporate. As you noticed, I gave up in the end.
Sometimes, rather than trying to code yourself out of a problem, it is best to start again. This may be one of those occasions. I'd still go the table route but change the structure.
So, three questions: Have you given all the permutations? Have you given all the permutations? Have you given all the permutations?
Sorry to be sarcastic but last time was a bit exasperating.
Formatting
Updated: Fixed typo