var key = "test";
html = html.replace(new RegExp("{{"+key+"}}","g"), key);
if_array = html.match(/<if>(.*?)<\/if>/g);
<if></if>
помещает в массив [data1, data2, data3]
package main
import (
"fmt"
"regexp"
)
func main() {
html := "{{test}}ing <if>abc</if> {{test}} <if>123</if>"
key := "test"
html = regexp.MustCompile("{{"+key+"}}").ReplaceAllString(html, key)
array_temp := regexp.MustCompile("<if>(.*?)</if>").FindAllStringSubmatch(html, -1)
var if_array []string
for _, val := range array_temp {
if_array = append(if_array, val[1])
}
fmt.Println(html)
fmt.Println(if_array)
}
package main
import (
"fmt"
"regexp"
"strings"
)
func main() {
var data string = `<if> {{t}} </if> {{s}}
<if> {{gg}} </if>`
var replace = map[string]string{
"t": "te",
"s": "ss",
"gg": "гг",
}
for key, value := range replace {
data = strings.Replace(data, "{{"+key+"}}", value, 2)
}
re := regexp.MustCompile("<if>(.*?)</if>")
if_array := re.FindAllString(data, -1)
fmt.Println(if_array[0] + "\n")
fmt.Println(if_array[1] + "\n")
}