Golf String's format() inverse Invert the Format method.

The Format method of the String class (or equivallent, such as sprintf) is available in most languages. It basically takes a "Format" string which may contain placeholders with some extra formatting, and zero or more values to be inserted instead of those placeholders.

Your task is to implement the inverse function in your language of choice.

API

Method name should be either format1 or deformat.

Input: 1st parameter will be the "Format" string, just like in the original format method. 2nd parameter will be the parsed string (see examples below). No other parameters are needed nor allowed.

Output: an array (or your language-of-choice's equivalent) of values that were extracted correspondingly with the placeholders in the format.

The placeholders are {0}, {1}, {2}, etc.

In case of bad format you may throw an error, or return whatever you like.

In case of invalid input, you may throw an error, or return whatever you like. Invalid input is such that cannot be generated by String.Format using same format string, for example: '{0}{0}', 'AAB'.

Examples

deformat('{0} {1}', 'hello world') =&gt; ['hello', 'world']
deformat('http{0}://', 'https://') =&gt; ['s']
deformat('http{0}://', 'http://') =&gt; [''] // array of one item which is an empty string
deformat('{0}{1}{0}', 'ABBA') =&gt; ['A', 'BB']


Ambiguity

In case of ambiguity you may return any suitable answer. For example:

deformat('{0} {1}', 'Edsger W. Dijkstra')
// both ['Edsger', 'W. Dijkstra'] and ['Edsger W.', 'Dijkstra'] are applicable.


Some More Rules


To make it easier, there's no need to actually support formatting. You can forget all about leading zeros, decimal point or rounding issues. Just generate the values as strings.
To make it non-trivial, Regular Expressions are not allowed.
You don't need to take care of curly braces in input (i.e. 2nd input parameter will not contain any {s or }s).


Winning

This is code-golf! (should be read as "This is Sparta!") the correct function having shortest length wins. Standard loopholes are forbidden.
Haskell, 220 characters

import Data.Map;f""""=[empty]
f('{':b)d=[insert k m b|(k,('}':a))&lt;-lex b,(m,c)&lt;-[splitAt n d|n&lt;-[0..length d]],b&lt;-f a c,notMember k b||b!k==m]
f(x:b)(y:d)|x==y=f b d;f _ _=[];format1 x y=elems$mapKeys((0+).read)$f x y!!0


Breaks if you use multiple representations for the same pattern ({1} vs {01}) - doesn't enforce their equality, discarding matches for all but one representation instead.

19 characters can be saved by omiting mapKeys((0+).read)$ if proper ordering of matches above 10 patterns doesn't matter, or if padding to the same length may be required, or if string ordering of patterns is acceptable. In any case, if a pattern is omitted from the first argument, it is omitted from the result as well.

Removing !!0 from the end makes format1 return the list of all solutions, rather than just the first one.

before golfing:

import Data.Map
import Control.Monad

cuts :: [a] -&gt; [([a],[a])]
cuts a=[splitAt n a | n &lt;- [0..length a]]

f :: String -&gt; String -&gt; [Map String String]
-- empty format + empty parsed = one interpretation with no binding
f "" "" = [empty]
-- template-start format + some matched = branch search
f ('{':xs) ys = do
    let [(key, '}':xr)] = lex xs
    (match, yr) &lt;- cuts ys
    b &lt;- f xr yr
    guard $ notMember key b || b!key == match
    return $ insert key match b
-- non-empty format + matching parsed = exact match
f (x:xs) (y:ys) | x == y = f xs ys
-- anything else = no interpretation
f _ _ = []

deformat :: String -&gt; String -&gt; [String]
deformat x y = elems $ mapKeys ((0+).read) $ head $ f x y