I want to replace regex-matched strings with new string but still keeping part of the original text.
I want to get
I own_VERB it and also have_VERB it
from
I own it and also have it
how do I do this with one line of code? I tried but can't get further than this. Thanks,
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
}