A simple solution might be to
- replace all format tokens with (.*)
- escape all other special charaters in
format
- make the regex match non-greedy
This would resolve the ambiguities to the shortest possible match.
(I'm not good at RegEx, so please correct me, folks :))