golang 如何用正则表达式组替换字符串?

How golang replace string by regex group?

我想使用正则表达式组来替换 golang 中的字符串,就像 python 中的一样:

re.sub(r"(\d.*?)[a-z]+(\d.*?)", r" ", "123abc123") # python code

那么我该如何在 golang 中实现它呢?

</code>、<code>等代替。例如:

re := regexp.MustCompile(`(foo)`)
s := re.ReplaceAllString("foo", "")
fmt.Println(s)

游乐场:https://play.golang.org/p/ZHoz-X1scf.

文档:https://golang.org/pkg/regexp/#Regexp.ReplaceAllString.