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
Regular expression to extract filename from given path in Golang
Regular expression to extract text between square brackets
Example: How to use ReadFull from IO Package in Golang?
How to use for and foreach loop?
Create and Print Multi Dimensional Slice in Golang
Golang Get current Date and Time in EST, UTC and MST?