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 read input from console line?
How to check if a string contains a substring in Golang?
Example of Sscan vs Sscanf vs Sscanln from FMT Package
Convert Int data type to Int16 Int32 Int64
Encoding and Decoding using json.Marshal and json.Unmarshal
How to check string contains uppercase lowercase character in Golang?