code: func SubstituteWith(template string, mapping Mapping, pattern *regexp.Regexp, subsFuncs ...SubstituteFunc) (string, error) {
  	var err error
  	result := pattern.ReplaceAllStringFunc(template, func(substring string) string {
  		matches := pattern.FindStringSubmatch(substring)
  		groups := matchGroups(matches, pattern)
  		if escaped := groups["escaped"]; escaped != "" {
  			return escaped
  		}
  
  		substitution := groups["named"]
  		if substitution == "" {
  			substitution = groups["braced"]
  		}
  
  		if substitution == "" {
  			err = &InvalidTemplateError{Template: template}
  			return ""
  		}
  
  		for _, f := range subsFuncs {
  			var (
  				value   string
  				applied bool
  			)
  			value, applied, err = f(substitution, mapping)
  			if err != nil {
  				return ""
  			}
  			if !applied {
  				continue
  			}
  			return value
  		}
  
  		value, _ := mapping(substitution)
  		return value
  	})
  
  	return result, err
  }
docs: // SubstituteWith subsitute variables in the string with their values.
  // It accepts additional substitute function.