package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`#[\w-]++(?<!#hashtag|#DoNotRemoveThis)(?=(?:\s+#[\w-]+)*\s*$)\s*`)
var str = `Any #hashtag in the middle of the string should NOT be removed regardless of what it is, for example #DoNotRemoveThis #KeepThisHashtag #toto and any hashtag at the end of the string should be removed UNLESS it matches the exeptions in the regex. #deletethis #DoNotRemoveThis #thismustgoaway`
var substitution = ""
fmt.Println(re.ReplaceAllString(str, substitution))
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Golang, please visit: https://golang.org/pkg/regexp/