Can NewReplacer.Replace do case insensitive string replacement?
r := strings.NewReplacer("html", "xml")
fmt.Println(r.Replace("This is <b>HTML</b>!"))
If not, what's the best way to do case insensitive string replace in Go?
Can NewReplacer.Replace do case insensitive string replacement?
r := strings.NewReplacer("html", "xml")
fmt.Println(r.Replace("This is <b>HTML</b>!"))
If not, what's the best way to do case insensitive string replace in Go?
You can use regular expressions for that:
re := regexp.MustCompile(`(?i)html`)
fmt.Println(re.ReplaceAllString("html HTML Html", "XML"))
Playground: http://play.golang.org/p/H0Gk6pbp2c.
It's worth noting that case is a thing that can be different depending on the language and locale. For example, the capital form of German letter "ß" is "SS". While this doesn't generally influence English texts, this is something to bear in mind when working with multi-lingual texts and programs that need to work them.