您甚至不需要捕获组。
package mainimport "fmt"import "regexp"func getverb(str string) string { var validID = regexp.MustCompile(`own|have`) return validID. ReplaceAllString(str, "${0}_VERB") }func main() { fmt.Println(getverb("I own it and also have it")) // how do I keep the original text like // I own_VERB it and also have_VERB it}${0}包含与整个模式匹配的字符串;${1}将包含与第一个子模式(或捕获组)匹配的字符串(如果有的话),您可以在Darka的答案中看到。


