I have a go string dbConnStr1 := "user=someone password=something host=superduperhost sslmode=something"
the k=v pair in this string may be in any order, for example: dbConnStr2 := "host=superduperhost user=someone password=something" Notice the difference in the key order and also the missing "sslmode" key in the second instance. Also, it is possible that instead of whitespace, the individual k,v pairs may be separated by newline too. It is safe to assume that the values may not contain '=' as a content. Given all these constraints: Now I want to extract the unique keys and their corresponding values from the given string, using regexp. If it will help, I can give a list of all the possible keys that may come (username, password, host, sslmode), but I would ideally like a regex solution that works with any list of keys and values. How to do this ? I understand that it may be possible with regexp.FindStringSubmatch but not able to wrap my head around writing the regexp. P.s: I know that instead of using regexp, I can write strings.Split call and do it normally, but I want a regexp based solution. Any help ? Thanks. PS: I have asked the same question in stackoverflow too and if you want to answer there, please see: https://stackoverflow.com/questions/44321199/golang-extract-unique-key-value-from-a-key-value-pair-string-using-regex -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.