我想用新字符串替换正则表达式匹配的字符串,但仍保留部分原始文本。
我想得到
I own_VERB it and also have_VERB it
从
I own it and also have it
我如何用一行代码做到这一点?我试过了,但不能比这更进一步。谢谢,
http://play.golang.org/p/SruLyf3VK_
package main
import "fmt"
import "regexp"
func getverb(str string) string {
var validID = regexp.MustCompile(`(own)|(have)`)
return validID. ReplaceAllString(str, "_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
}