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 fix race condition using Atomic Functions in Golang?
How to print struct variables data in Golang?
How to convert Colorful PNG image to Gray-scale?
How to verify a string only contains letters, numbers, underscores, and dashes in Golang?
How to read names of all files and folders in current directory?
Golang HTTP GET request with parameters