Golang ProgramsGolang Programs

Replace any non-alphanumeric character sequences with a dash using Regex

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)
}
C:\golang\coding>go run example10.go
-Golang-Python-Php-Kotlin-

C:\golang\coding>