Last active
April 20, 2025 11:52
Revisions
-
ik5 revised this gist
Jun 24, 2024 . No changes.There are no files selected for viewing
-
ik5 created this gist
Jun 24, 2024 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,45 @@ package main // go play with my original code: https://go.dev/play/p/dt8WFHM1E8d import ( "fmt" "regexp" ) var validLPA = []string{ `LPA$www1.a.google.com$ABC1`, `LPA$www1.a.google.com$ABC1-X$1.1.1$1`, `LPA$www1.a.google.com$ABC1$$1`, `LPA$www1.a.google.com$ABC1$10000.2.3333333`, } const activationCodeRegex = `^((?P<LPA>LPA)\$(?P<FQDN>([a-zA-Z0-9]{1}[a-zA-Z0-9-]{0,62})(\.[a-zA-Z0-9]{1}[a-zA-Z0-9-]{0,62})*?(\.[a-zA-Z]{1}[a-zA-Z0-9]{0,62})\.?)\$(?P<AC_TOKEN>[A-Z0-9-]+)(\$(?P<OID>([0-9]+)(\.[0-9]+)*)?(\$(?P<CONFIRMATION_CODE>1))?)?$)` var ( activationCodeRegexp = regexp.MustCompile(activationCodeRegex) groupNames = activationCodeRegexp.SubexpNames() ) func main() { fmt.Printf("groupNames: %+#v\n", groupNames) var ( matches [][]string result []map[string]string ) for _, lpaString := range validLPA { matches = activationCodeRegexp.FindAllStringSubmatch(lpaString, -1) fmt.Printf("%s - %#+v\n", lpaString, matches) var tmpMap = map[string]string{} for idx, name := range groupNames { if name != "" && idx > 0 { tmpMap[name] = matches[0][idx] } } result = append(result, tmpMap) } fmt.Printf("result: %+#v\n", result) }