func NewTemplateFormatter(template string, captureCount int) *TemplateFormatter {
	matches := templateReplaceCaptureRE.FindAllStringSubmatch(template, -1)
	if len(matches) == 0 {
		return &TemplateFormatter{captureCount: 0, fmtString: template}
	}
	var indexes []int
	valueFormatter := template
	for _, match := range matches {
		idx, err := strconv.Atoi(match[len(match)-1])
		if err != nil || idx > captureCount || idx < 1 {
			valueFormatter = strings.Replace(valueFormatter, match[0], "", -1)
		} else {
			valueFormatter = strings.Replace(valueFormatter, match[0], "%s", -1)
			indexes = append(indexes, idx-1)
		}
	}
	return &TemplateFormatter{
		captureIndexes: indexes,
		captureCount:   len(indexes),
		fmtString:      valueFormatter,
	}
}
NewTemplateFormatter instantiates a TemplateFormatter
from given template string and the maximum amount of captures.
package fsm
import (
	"fmt"
	"regexp"
	"strconv"
	"strings"
)
var (
	templateReplaceCaptureRE = regexp.MustCompile(`\$\{?([a-zA-Z0-9_\$]+)\}?`)
)
type TemplateFormatter struct {
	captureIndexes []int
	captureCount   int
	fmtString      string
}