gitee.com/zhongguo168a/gocodes@v0.0.0-20230609140523-e1828349603f/datax/stringx/replace.go (about)

     1  package stringx
     2  
     3  import (
     4  	"gitee.com/zhongguo168a/gocodes/datax/mapx"
     5  	"regexp"
     6  	"strings"
     7  )
     8  
     9  // ${_id}:${内网地址}
    10  func ReplaceForamtTypeScript(format string, obj map[string]interface{}) string {
    11  	结果 := format
    12  	变量集合正则 := regexp.MustCompile(`\$\{([一-龥A-Za-z0-9_]+)}`)
    13  	变量集合 := 变量集合正则.FindAllStringSubmatch(format, -1)
    14  
    15  	for i := 0; i < len(变量集合); i++ {
    16  		变量数组 := 变量集合[i]
    17  		替换名字 := 变量数组[0]
    18  		变量名字 := 变量数组[1]
    19  		结果 = strings.Replace(结果, 替换名字, mapx.String(obj, 变量名字), -1)
    20  	}
    21  
    22  	return 结果
    23  }