Files
Mike Cohen 6761ef16a6 Added the ability to load artifact packs. (#458)
Users can now upload artifact packs from an external ZIP file into the
GUI. All external artifacts are added to a "Packs" namespace.
2020-06-26 02:36:24 +10:00

21 lines
440 B
Go

package utils
import "regexp"
func ReplaceAllStringSubmatchFunc(re *regexp.Regexp, str string, repl func([]string) string) string {
result := ""
lastIndex := 0
for _, v := range re.FindAllSubmatchIndex([]byte(str), -1) {
groups := []string{}
for i := 0; i < len(v); i += 2 {
groups = append(groups, str[v[i]:v[i+1]])
}
result += str[lastIndex:v[0]] + repl(groups)
lastIndex = v[1]
}
return result + str[lastIndex:]
}