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)
我想使用正则表达式组来替换 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)