3

提取/替换短信模板参数 - Go语言中文网 - Golang中文社区

 1 year ago
source link: https://studygolang.com/articles/35942
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

提取/替换短信模板参数

osummer · 大约5小时之前 · 45 次点击 · 预计阅读时间 1 分钟 · 大约8小时之前 开始浏览    

使用reg包正则匹配

func main() {
    str := "您好!您有一份来自${enterprise}的签署文件:https://xxx.net/${sign_url},请于收到短信后的48小时内点击以上链接完成相关合同签署。签署流程:https://xxx.net/${sign_flow_url}。如有疑问,请联系大区SSC。"
    var p []string
    var FieldRegex = regexp.MustCompile(`\${[a-zA-Z0-9-_.]+}`)

    file := FieldRegex.ReplaceAllStringFunc(str, func(str string) (field string) {
        p = append(p,str[2 : len(str)-1])
        return
    })
    params, err := json.Marshal(&p)
    if err != nil {
        return
    }
    fmt.Println(string(params))
    fmt.Println(file)
}

// 打印结果
["enterprise","sign_url","sign_flow_url"]
您好!您有一份来自的签署文件:https://pb.vanhr.net/,请于收到短信后的48小时内点击以上链接完成相关合同签署。签署流程:https://vanhr.net/。如有疑问,请联系大区SSC。

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK