replaceRE gives syntax error

There are two layers of interpretation here. One is Go template strings and the other is regular expressions.

For Go strings, the Go spec is helpful. See https://golang.org/ref/spec#String_literals. Literal strings use the back tick. Interpreted strings use the double quote.

Escaping the parenthesis is needed for the regexp pattern itself and has little to do with Go.

As @alexandros said, I almost always use literal strings when building regexp patterns in Go or Hugo.

2 Likes