正则分组替换,用$1,$2代替匹配到的字符串
func main() { re,_ := regexp.Compile(`a=(\d+),b=(\d+)`) c := re.ReplaceAllString("test regexp a=1234,b=5678. test regexp replace a=8765,b=3210 ","c=$2,d=$1") fmt.Println(c) }
输出:
test regexp c=5678,d=1234. test regexp replace c=3210,d=8765原文链接:https://www.f2er.com/go/191326.html