Go regexp: match three asterisks
go
Solution
Adding to @VonC's answer, regexp aren't always the answer and are generally slower than using `strings.*`.
For a complex expression, sure regexp is awesome, however if you just want to match a string and replace it then, `strings.Replacer` is the way to go:
var asterisksReplacer = strings.NewReplacer(`* * *`, `<hr>`)
func main() {
fmt.Println(asterisksReplacer.Replace(`xxx * * * yyy *-*-* zzz* * *`))
}
playground
Problem
So I did this: ``` r, _ := regexp.Compile("* * *") r2 := r.ReplaceAll(b, []byte("<hr>")) ``` and got: ``` panic: runtime error: invalid memory address or nil pointer dereference ``` So I figured I had to escape them: ``` r, _ := regexp.Compile("\* \* \*") ``` But got `unknown escape secuence` I'm a Go Beginner. What am I doing wrong?