How to create regexp pattern from constants and variables?
import (
"fmt"
"regexp"
)
const (
NBSP = "xA0"
NBSP_UTF8 = "xC2xA0"
NBSP_UTF16 = "x00xA0"
)
func main(){
var re = regexp.MustCompile(NBSP_UTF16+"|"+NBSP_UTF8+"|"+NBSP)
fmt.Println(re)
}
Here I want to create a pattern that match all occurrences of 3 different variants of non-breaking spaces and replace them with a normal space
panic: regexp: Compile("x00xa0|u00a0|xa0"): error parsing regexp: invalid UTF-8: `▒| |▒` [recovered]