I'm trying to split a syslog message into a key:value 'map[string]string', but cannot seem to get the regex right.
The source string delimits its keys and values by an '='. However, each pair is seperated by spaces with spaces actually being within the values. I have it pretty close but as you can see from the link below, I can't get the rest of the 'start', 'end', or 'suser' values.
Here's a link to a golang playground showing my exact problem:
package main
import (
"fmt"
"regexp"
)
var rex = regexp.MustCompile("(\\w+)=(.+?[^\\\\s\\\\w+=]+)")
func main() {
conn := "start=Mar 26 2019 10:36:14 +00:00 end=Mar 26 2019 10:36:14 +00:00 suser=AD.COM\\\\Username src=10.1.0.51"
data := rex.FindAllStringSubmatch(conn, -1)
res := make(map[string]string)
for _, kv := range data {
k := kv[1]
v := kv[2]
res[k] = v
}
for v := range res {fmt.Printf("%s: %v
", v, res[v])}
}