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 all Non-Alphanumeric Characters from a String
Split a string at uppercase letters using regular expression in Golang
Regular expression to validate common Credit Card Numbers
How to extract text from between html tag using Regular Expressions in Golang?
Regular expression to extract text between square brackets
Regular expression to validate phone number