Replace any non-alphanumeric character sequences with a dash using Regex
Example
package main
import (
"fmt"
"log"
"regexp"
)
func main() {
reg, err := regexp.Compile("[^A-Za-z0-9]+")
if err != nil {
log.Fatal(err)
}
newStr := reg.ReplaceAllString("#Golang#Python$Php&Kotlin@@", "-")
fmt.Println(newStr)
}
Output
-Golang-Python-Php-Kotlin-
Most Helpful This Week
How to declare empty Map in Go?
How to use wildcard or a variable in our URL for complex routing?
How to convert Boolean Type to String in Go?
How to check if a string contains certain characters in Golang?
Different ways to validate JSON string
Convert specific UTC date time to PST, HST, MST and SGT
Anonymous Functions in Golang
Converting Int data type to Float in Go
How to check if a string contains a white space in Golang?
How to reads and decodes JSON values from an input stream?