Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Golang replace string using regular expression (regex)
package main
import (
func main() {
re := regexp.MustCompile(`[^a-zA-Z0-9]`)
slug := strings.ToLower(re.ReplaceAllString("hello world", "-"))
fmt.Println(slug) // "hello-world"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.