github.com/qiuhoude/go-web@v0.0.0-20220223060959-ab545e78f20d/prepare/06_xmljson/reg/expand/expand.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "regexp" 6 ) 7 8 func main() { 9 src := []byte(` 10 call hello alice 11 hello bob 12 call hello eve 13 `) 14 re := regexp.MustCompile(`(?m)(call)\s+(?P<cmd>\w+)\s+(?P<arg>.+)\s*$`) 15 var res []byte 16 for _, s := range re.FindAllSubmatchIndex(src, -1) { 17 res = re.Expand(res, []byte("$cmd('$arg')\n"), src, s) 18 } 19 fmt.Println(string(res)) 20 }