golang 正则表达式

来源:互联网 发布:魔音变声软件 编辑:程序博客网 时间:2024/05/22 00:48

正则分组替换,用$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