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
Replace first occurrence of string using Regexp
How to extract text from between html tag using Regular Expressions in Golang?
Regular Expression to get a string between parentheses in Golang
Regular expression to extract date(YYYY-MM-DD) from string
Regular expression to extract all Non-Alphanumeric Characters from a String
Regular expression to validate common Credit Card Numbers