Last active
April 20, 2025 11:52
-
-
Save ik5/8ba321a549523c7b1ceafe9da85df808 to your computer and use it in GitHub Desktop.
LPA (Activation Code) string is the QR code you scan for provision eSIM to your telephone. The following code parse the string to it's elements based on GSMA standard.
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 | |
// 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) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment