Using regex in golang, I'd like to replace all non-alphanumeric characters of any languages with -
, in order to make pretty urls:
Here is one of many regex that I've tried:
package main
import (
"fmt"
"regexp"
)
const sample = `سلام دنیا hello world 1 %^&`
func main() {
var re = regexp.MustCompile(`~[\p{L}0-9\s]+`)
s := re.ReplaceAllString(sample, `-`)
fmt.Println(s)
}
The output should be:
سلام-دنیا-hello-world-1
But it does not work. How can I fix it?