You are reading a single comment by @Velocio and its replies. Click here to read the full conversation.
  • I've put in a solution that may work, but it might have unintended side effects too.

    I figure the best way to find out is to ship it and see: http://play.golang.org/p/JNHj3PtZaO

    package main
    
    import "fmt"
    import "regexp"
    import "strings"
    
    var (
    	regMentions = regexp.MustCompile(`(?:^|\W)([+@](\S+))`)
    	regSpecial  = regexp.MustCompile("([\\\\_*{}[\\]()#-.!])")
    	replSpecial = `\$1`
    )
    
    func main() {
    	str := `@_d\a*n)]_ foo +_dan_ +_dan_`
    
    	fmt.Println(str)
    
    	for _, s := range regMentions.FindAllString(str, -1) {
    		str = strings.Replace(str, s, regSpecial.ReplaceAllString(s, replSpecial), 1)
    	}
    
    	fmt.Println(str)
    }
    

    @dan should now work

About

Avatar for Velocio @Velocio started