Skip to content

Instantly share code, notes, and snippets.

@gomes
Created August 15, 2018 15:21
Show Gist options
  • Save gomes/2af6e654ed1d9b2c9cf1034c8cf501a5 to your computer and use it in GitHub Desktop.
Save gomes/2af6e654ed1d9b2c9cf1034c8cf501a5 to your computer and use it in GitHub Desktop.
Simple regex to convert camel case to snake_case in Go
package main
import (
"fmt"
"regexp"
"strings"
)
func main() {
re := regexp.MustCompile(`([a-z0-9])([A-Z])`)
s := re.ReplaceAllString("HealthChecksResultsFulanoOutroBeltrano", "${1}_${2}")
fmt.Println(strings.ToLower(s))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment