Created
August 15, 2018 15:21
-
-
Save gomes/2af6e654ed1d9b2c9cf1034c8cf501a5 to your computer and use it in GitHub Desktop.
Simple regex to convert camel case to snake_case in Go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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