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
Strip all white spaces, tabs, newlines from a string
Example to handle GET and POST request in Golang
Golang Read Write and Process data in CSV
Example to create custom error
How to convert Boolean Type to String in Go?
Runtime package variables
How to check pointer or interface is nil?
Get Set and Clear Session in Golang
Example: How to use ReadFull from IO Package in Golang?
How to iterate over a Map using for loop in Go?